Php 将URL参数中的值传递到标头:位置重定向

Php 将URL参数中的值传递到标头:位置重定向,php,redirect,header,http-status-code-301,Php,Redirect,Header,Http Status Code 301,以下是我想要实现的目标: <?php header("Location: http://www.example.com"); ?> <?php if (!empty($_GET['url'])) { header("Location: " . $_GET['url']); exit(); } else { # print the whole $_GET arrays # just for debug ! print_r($_GE

以下是我想要实现的目标:

<?php
    header("Location: http://www.example.com");
?>
<?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/
1)开幕式

2.)应重定向到:

(测试)到目前为止,在out.php中这是有效的:

<?php
    header("Location: http://www.example.com");
?>
<?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/
输出:

<?php
    header("Location: http://www.example.com");
?>
<?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/

输出:

<?php
    header("Location: http://www.example.com");
?>
<?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/

输出:

<?php
    header("Location: http://www.example.com");
?>
<?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/

提示:该文件夹不包含任何其他文件

检查
$\u 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.");
}
?>


除了代码之外,请尝试更清楚地说明哪些不起作用(例如,您收到错误消息等)-我们没有水晶球…

它是如何起作用的?发送错误消息,只是什么都不做,…?问题中的输出已更新,请看一看,谢谢我更新了问题,请看一看(我也尝试了你的方法,但结果是一样的)屏幕上也没有调试文件或打印,如果我打开文件out.php本身,我得到的结果是:
Array()此字段为空。
正如我在向参数添加值时在输出中所解释的,它redirects@user1679901. 奇怪:获取
Array()
意味着您的
url
查询参数为空(或不存在),而如果您真的使用了@Jan的所有解决方案(即以
if(!empty($\u GET['url'))
)开头),则不会发生这种情况!我建议替换
print\r($\u-GET)通过
echo$\u服务器['QUERY\u STRING']
@user1679901:请将您完整的
out.php
code.@cFreed还尝试了
echo$\u服务器['QUERY\u STRING']
但也重定向回它返回屏幕上的消息
此字段为空。
当我刚刚打开go.php文件时itself@mikulabc. 当我建议替换
print\r($\u GET)时,我的意思是什么通过
echo$\u服务器['QUERY\u STRING']
不是使代码按预期工作的解决方案,而是查看回送的查询字符串,以控制传输的信息。那么在
这个字段为空之前它打印了什么。