Contact ZenDuo


Returning the Current Page URL



Using PHP you can return the current url of the page by simply using :

$pageURL = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
echo $pageURL;

By using string manipulation you can also us this function to return the end characters of the url request.

For the following url: http://zenduo.co.uk/folder/page.php?g2_itemId=89 we can return the end numbers using the following code:

$pageURL = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
$pageURL = substr($pageURL,strrpos($pageURL,"=")+1);
echo $pageURL;

The result of this would be 89.

This entry was posted on Tuesday, September 29th, 2009 at 7:12 pm and is filed under PHP Scripts. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply