techfolks php tutorials logo
PHP Sample Programs

How to Get Current Page URL Using PHP

If you would like to know from which page the request has come from using post Method then there is a simple PHP script can solve your issue.

Get Current Page URL Using PHP

Check below script to Get Current page using PHP

function getCurrentURLPage()

	$s = empty($_SERVER["HTTPS"]) ? '': ($_SERVER["HTTPS"] == "on") ? "s" : "";

	$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;

	$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);

	return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];

echo getCurrentURLPage();