// Follow $_SERVER variables was set only for test $_SERVER['HTTPS'] = 'off';// on $_SERVER['SERVER_PORT'] = '9999'; // Setup $_SERVER['HTTP_HOST'] = 'some.crazy.server.5.name:8088';// Port is optional there
$_SERVER['REQUEST_URI']='/150/tail/single/normal?get=param';
echo getCurrentUrl();// http://some.crazy.server.5.name:9999/150/tail/single/normal?get=param
echo getCurrentUrl(false);// http://some.crazy.server.5.name:9999/
//Fetch page URL by this
$url = $_SERVER['REQUEST_URI'];
echo "$url<br />";//It will print//fetch host by this
$host=$_SERVER['HTTP_HOST'];
echo "$host<br />";//You can fetch the full URL by this
$fullurl ="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $fullurl;
[ad type=”banner”]
You can use this code:
php code
print_r($_SERVER);
$_SERVER is an array containing information such as headers, paths, and script locations.
The entries in this array are created by the web server.
$HTTP_SERVER_VARS contains the same initial information, but is not a superglobal. (Note that $HTTP_SERVER_VARS and $_SERVER are different variables.)
Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.