hi I have a javascript file in which I am trying to give the path of the image to it in php like,
var arrowimages = {
down:['downarrowclass', '<?php echo $_SERVER[REMOTE_HOST]; ?>/ultimate-legal-aid/administrator/down.gif', 23],
right:['rightarrowclass', '<?php echo $_SERVER[REMOTE_HOST]; ?>/ultimate-legal-aid/administrator/right.gif']
}
but it not works.
plz help me to define the path in a correct way.
The fact that it doesn’t work has nothing to do with how you embed PHP in javascript. Before I explain what’s going on, I’d like to make sure that you know the difference between a client side language, and a server side language.
When a user enters the URL of a page and hits enter, a request for that page is sent to your web server. Because of the way your server is configured, this request will tell the serevr to run a PHP script. PHP is a server side language. That means that the user will never see your PHP code. Whatever this PHP script outputs, wether it is HTML, CSS, Javascript, or some other kind of file, will be sent to the user.
If your output contains javascript, this will be executed by the user’s browser once it has been downloaded. This means that in the code snippet you gave, the PHP script will output
Now, these numbers you see will probably not be 12.12.12.12, but some other series of numbers with dots in between them. This is an IP address. More specifically, it’s the user’s ip addres. So, the path this outputs, would be a path on the user’s computer, and the user most likely doesn’t have a web server running, so this won’t give you any image. You should replace that line with this one: