How can I get the current browser url in PHP ? I know a code $_SERVER["HOST"] which is not working. Please advice.
$_SERVER["REQUEST_URI"] PHP: Also, try <?php phpinfo(); ?> PHP: it will show you all available global variables.
Hey buddy. thanks a lot. So this global variable differ in one server to another ? $_SERVER["REQUEST_URI"] PHP: is not working, $_SERVER["SERVER_NAME"] PHP: show me the full path url.
Yes, these variables can vary from server to server, that's why most scripts require you to enter full path of your script location during setup.
Well if you want the exact URL as in the address bar of the browser, you will have to use: <?php $url_in_the_address_bar=$_SERVER['SERVER_NAME']. SERVER['REQUEST_URI']; ?> PHP: Many times, it may be possible that an application is using re-written URL, such as http://www.domain.com/computers/laptops/lenovo Code (markup): The actual PHP script may be hidden behind the URL. In such cases, the hidden URL can be obtained from <?php $hidden_url=$_SERVER['SERVER_NAME']. SERVER['SCRIPT_NAME']; ?> PHP:
$url=(!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; Code (markup): This is the string i used for finding address bar url. Hope it helps!