In this Post, you’ll learn how to get current web page url from your web browser address bar using php script.
function getUrl() { $url = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["HTTP_HOST"] : 'https://'.$_SERVER["HTTP_HOST"]; $url .= ( $_SERVER["SERVER_PORT"] !== 80 ) ? ":".$_SERVER["SERVER_PORT"] : ""; $url .= $_SERVER["REQUEST_URI"]; return $url; }
By calling above function you get the current page url.
Over view
1. $_SERVER[“HTTPS”] – this will show on for https
2. $_SERVER[“SERVER_PORT”] – This will show Port Number.
3. $_SERVER[‘HTTP_HOST’] – This will show only server name.
4. $_SERVER[‘REQUEST_URI’] – This will show you the path to file of your url.