Friday, January 27, 2012

[PHP] Get Whole URL in Address Bar

Sample URL: http://www.google.com/pacman/


We will use two PHP functions:
$_SERVER['HTTP_HOST']

$_SERVER['REQUEST_URI']

Code 1:
echo $_SERVER['HTTP_HOST'];

Output:
www.google.com


Code 2:
echo $_SERVER['REQUEST_URI']
Output:
/pacman/


To get the whole URL:
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
Output:
http://www.google.com/pacman/

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...