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']
不是使代码按预期工作的解决方案,而是查看回送的查询字符串,以控制传输的信息。那么在这个字段为空之前它打印了什么。
?