How do I capture the whole URL using PHP?
Possible Duplicate:
PHP Get the Full URL
How do I capture the whole URL using PHP?
I would like to the whole of the URL including the _GET variable names and values, for example www.mywebsite.com/store.php?department=MENS
The code I have used below only gives me the URL without the _GET variable part.
$url = $_SERVER['SERVER_NAME'];
$page = $_SERVER['PHP_SELF'];
$page = $_POST['url'];
echo "http://".$url.$page;
All I would like is to be able to copy that URL exactly how it is.
function currenturl() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
simply do $url=currenturl(); that's it
$url = (!empty($_SERVER['HTTPS']))
? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']
: "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
链接地址: http://www.djcxy.com/p/42276.html
上一篇: 我如何在PHP中获得完整的URL,而不仅仅是它的一部分?
下一篇: 如何使用PHP捕获整个URL?