我有下面的代码
if ($_REQUEST['referer_url'] == "" ) {
header("location: index.php");
exit;
}
header('location: http://' . $_REQUEST['referer_url']);
exit;我得到了错误Warning: Header may not contain more than a single header, new line detected。这是因为它在标题中添加了一个新行。我尝试像这里在堆栈溢出时建议的那样执行一个urlencode,但是它将我重定向到一个没有找到错误的服务器,它在url中包含了一个包含undefined index的奇怪url。我还能尝试什么来维护$_REQUEST['referer_url']呢?
发布于 2014-05-07 07:19:57
试试这个:
$redirect_url = isset($_SERVER['HTTP_REFERER']) &&
!empty($_SERVER['HTTP_REFERER']) ?
$_SERVER['HTTP_REFERER'] : 'index.php';
header("Location: $redirect_url");
exit;发布于 2014-05-07 07:27:27
首先需要检查您在$_REQUEST['referer_url']中得到了什么,如果您有完整的url,那么从条件中删除http://,如果是空的,它将重定向到index.php,尝试
$redirect = (!empty($_REQUEST['referer_url']) ? 'http://'.$_REQUEST['referer_url'] : 'index.php');
header("location: $redirect");
exit;发布于 2014-05-07 07:30:01
有没有试过修剪裁判员?
$myRefererUrl = trim($_REQUEST['referer_url']);
header('location: '.(($myRefererUrl=='')?'index.php':$myRefererUrl));
exit;使用trim,您可以去掉字符串中的换行符;)
https://stackoverflow.com/questions/23511157
复制相似问题