[英]Get Querystring values from Location Header in PHP
更新
假設我的用戶訪問了此頁面:
https://www.abc.com/mypage.php
該頁面的響應頭是:
Content-Length 28
Date XXXX
Location https://abc.com/error.php?target=https%3A%2F%2Fabc.com%2Fmypage.php&
errorReason=Go+To+this+Url
Server MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
這意味着頁面正在使用Location
標頭中的querystring參數重定向到https://www.abc.com/errorpage.php
。
現在在errorpage.php上,而不是使用$ _GET獲取querystring參數,我想獲取Location標頭,解析出參數並打印出來。
$ _GET的缺點是,我的用戶可以在querystring中輸入任何廢話,而我的errorpage.php會打印出來。 所以我想通過檢測Location標頭來避免這種情況。
有什么辦法可以從重定向中獲取Location標頭? 我沒有看到使用getallheaders()或任何其他PHP函數。
謝謝
我不確定您是否正在尋找除簡單$_GET
之外的其他東西?
$target = $_GET['target'];
$errorReason = $_GET['errorReason'];
如果您正在執行腳本:
$target = $_GET['target']; $errorReason = $_GET['errorReason'];
如果您只有URL:
$url = "https://abc.com/pageredirect.php?target=https%3A%2F%2Fabc.com%2Fredirecttopage.php&errorReason=Simple+redirect";
$urlObj = parse_url($url);
$getVars = $urlObj['query'];
parse_str($getVars);
echo "Target: ".$target." and errorReason: ".$errorReason;
您可以使用$_GET
數組獲取這些URL參數:
$_GET['target'];
$_GET['errorReason'];
參數在$_GET
變量中
$_GET['target'];
$_GET['errorReason'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.