We can use PHP SERVER variables to get full address bar URL inside PHP script.
Simple way
1 2 3 4 |
<?php $currenturl = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $currenturl; ?> |
With Protocol and port …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?php function currenturl() { $protocol_suffix = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$protocol_suffix; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } echo currenturl(); ?> |
Please refer http://php.net/manual/en/reserved.variables.server.php for PHP SERVER variables.