以下是我想要达到的目标:
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输出
提示:该文件夹不包含任何其他文件
答案 0 :(得分:0)
检查$_GET
数组()中是否有确实的内容。在标题重定向后进行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.");
}
?>
除了代码之外,还要尝试更清楚地说明哪些不起作用(例如,您收到错误消息等) - 我们没有水晶球......