How to get current page full URL with PHP
In mostly case we might be need current url of the page with PHP in user log in authentication functionality. when a user go for log in page, after successfull log in the user we should return the user to same page where he came from . this is same for log out scenario also. We need this current page url in cross site cummunication also. So i wrote a small php function to get the current url of the working page.
function current_url() { if (!isset($_SERVER['REQUEST_URI'])) { $serverrequri = $_SERVER['PHP_SELF']; } else { $serverrequri = $_SERVER['REQUEST_URI']; } /** * server request uri depends upon server OS version */ $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; /** * get protocal if SSL enabled. */ $serverprotocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/") . $s; $serverport = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":" . $_SERVER["SERVER_PORT"]); /** * Page might be run with IP and Port also like 127.0.0.1:8080 */ return $serverprotocol . "://" . $_SERVER['SERVER_NAME'] . $serverport . $serverrequri; } |
By calling above function you get the current page url and you pass this url to log in and log out page with return get parameter with base64_encode and send back user to by base64_decode .

