首頁  >  文章  >  後端開發  >  php如何取得跳轉前的url

php如何取得跳轉前的url

coldplay.xixi
coldplay.xixi原創
2020-08-11 10:34:083755瀏覽

php取得跳轉前的url方法:1、取得URL帶QUESTRING參數的JAVASCRIPT客戶端方法;2、正規分析法,設定或取得整個URL為字串,程式碼為【alert(window. location.href)】。

php如何取得跳轉前的url

php取得跳轉前的url方法:

一:取得URL帶QUESTRING參數的JAVASCRIPT客戶端解決方案,相當於asp的request.querystring,PHP的$_GET

#1.函數:

2.然後透過呼叫此函數取得對應參數值:

以此取得url字串中所帶的同名參數

二、正規分析法。

function GetQueryString(name) {
var reg = new
RegExp("(^|&)" + name +
"=([^&]*)(&|$)","i");
var r =
window.location.search.substr(1).match(reg);
if (r!=null) return
(r[2]); return null;
}
alert(GetQueryString("参数名1"));
alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));

其他參數取得介紹:

//設定或取得物件指定的檔案名稱或路徑。

alert(window.location.pathname);

//設定或取得整個 URL為字串。

alert(window.location.href);

//設定或取得與 URL關聯的連接埠號碼。

alert(window.location.port);

//設定或取得 URL的協定部分。

alert(window.location.protocol);

//設定或取得 href屬性在井號「#」後面的分段。

alert(window.location.hash);

//設定或取得 location 或 URL 的hostname 和 port 號碼。

alert(window.location.host);

//設定或取得 href屬性中跟在問號後面的部分。

alert(window.location.search);

相關學習推薦:php程式設計(影片)

以上是php如何取得跳轉前的url的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn