javascript實作:
top.location.href 頂層視窗的位址
this.location.href 目前視窗的位址
PHP實作
測試網址:http://localhost/blog/testurl.php?id=5
//取得網域或主機位址
echo $_SERVER['HTTP_HOST'].”
輸出localhost
//取得網頁位址
echo $_SERVER['PHP_SELF'].”
輸出/blog/testurl. php
//取得網址參數
echo $_SERVER[“QUERY_STRING”].”
輸出id=5
echo $_SERVER['HTTP_REFERER'].”
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI' ];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
輸出http://localhost /blog/testurl.php?id=5
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER[ “SERVER_PORT”].$_SERVER[“REQUEST_URI”];
輸出http://localhost:80/blog/testurl.php?id=5
$url ='http://'.$_SERVER['SERVER_NAME'].$_SERVER[“REQUEST_URI”];
echo
dirname($url);輸出http://localhost/ blog
以上是如何利用 php 取得頁面參數方法匯總的詳細內容。更多資訊請關注PHP中文網其他相關文章!