[英]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.