我想重定向到一些页所以我尝试这样。
www.example.com/logout.php?redirect=www.index-page.com/index.php
echo $redirect = "'Location: http://".$_GET['redirect']."'";
//redirects to index
header($redirect);
但它不适用于我。是否有任何建议。
我想重定向到一些页所以我尝试这样。
www.example.com/logout.php?redirect=www.index-page.com/index.php
echo $redirect = "'Location: http://".$_GET['redirect']."'";
//redirects to index
header($redirect);
但它不适用于我。是否有任何建议。
事情是这样的:
在退出链接:
<a href="http://www.example.com/logout.php?redirect=<?=urlencode('http://www.index-page.com/index.php')?>"> Logout </a>
在logout.php页:
<?
// destroy session
header('location:'.urldecode($_GET['redirect']));
die();
?>
你不应该需要额外的'
$redirect = "Location: http://".$_GET['redirect'];
不能使用echo
头前,如果没有它会产生Warning: Cannot modify header information - headers already sent by
$redirect = "Location: http://". $_GET['redirect'];
header($redirect);
您只能使用redirect
无echo
:
header("Location: http://".$_GET['redirect']);
的问题是在这里
echo $redirect = "'Location: http://".$_GET['redirect']."'";
//redirects to index
header($redirect);
你不应该有头前使用的回声,这将导致警告header already sent
。
使用方法如下
$redirect = "Location: http://".$_GET['redirect'];
//redirects to index
header($redirect);
下面是用户重定向到谷歌
$link='http://Google.com';
header("location: $link");
你可以把它的功能
function redirectUser($link){
header("location: $link");
}
一个例子,那么你可以把它叫做像
redirectUser('http://google.com');
或者
echo redirectUser('http://google.com');
没有错误会发生!
我建议你使用die();
重定向代码后,中止代码正在添加
这首先需要进行基本的调试,请记录(和/或显示)错误并查看PHP错误日志。此外,您将在重复问题中了解更多信息。 – hakre