![](/img/trans.png)
[英]Passing Parameter from URL string in Header() redirect to another page in PHP
[英]Passing a Value from a URL Parameter to Header:Location redirect
這是我要實現的目標:
1.)打開http://example.org/go.php?url=http://www.example.com
2.)應該將301重定向到: http : //www.example.com
(測試)到目前為止,在out.php中,此方法有效:
<?php
header("Location: http://www.example.com");
?>
所以我繼續將這段代碼放在go.php中:
<?php
if (!empty($_GET['url'])) {
header("Location: " . $_GET['url']);
exit();
} else {
# print the whole $_GET arrays
# just for debug !
print_r($_GET);
die("This field is empty.");
}
?>
它不起作用,這是我得到的:
A redirect to http://example.org/
http://example.org/go.php?url=http://www.example.com輸出:
提示:該文件夾不包含任何其他文件
檢查$_GET
array()中是否確實有東西。 具有exit();
也是一種好習慣exit();
標頭重定向后調用。
<?php
if (!empty($_GET['url'])) {
header("Location: " . $_GET['url']);
exit();
} else {
# print the whole $_GET arrays
# just for debug !
print_r($_GET);
die("This field is empty.");
}
?>
除了代碼之外,請嘗試弄清楚到底什么不起作用(例如,您收到錯誤消息等)-我們沒有水晶球。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.