PHP代码获取网址参数的数据,请收藏。
<?
echo $_SERVER['HTTP_HOST']."<br>"; #localhost
echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php
echo $_SERVER["QUERY_STRING"]."<hr>"; #id=5
echo $_SERVER['HTTP_REFERER']."<br>";
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."<br>";
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']."<br>";
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]."<br>";
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]."<br>";
echo dirname($url);
?>
举例,https://www.woailunwen.com/list.php?id=4
会获取到:
https://www.woailunwen.com也会获取到list.php?id=4
赞 (0)