php 收到警告“标题可能不包含多个标题,检测到新行”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16320403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getting warning "Header may not contain more than a single header, new line detected"
提问by nav
I am doing coding in oops for uploading image in PHP. But After submit image, it's giving warning
我正在用 oops 进行编码,以便在 PHP 中上传图像。但是提交图像后,它发出警告
"Header may not contain more than a single header, new line detected"
“标题不能包含多个标题,检测到新行”
Below is my function, on which its giving error
下面是我的函数,它给出了错误
public function ft_redirect($query = '') {
if (REQUEST_URI) {
$_SERVER['REQUEST_URI'] = REQUEST_URI;
}
$protocol = 'http://';
if (HTTPS) {
$protocol = 'https://';
}
if (isset($_SERVER['REQUEST_URI'])) {
if (stristr($_SERVER["REQUEST_URI"], "?")) {
$requesturi = substr($_SERVER["REQUEST_URI"], 0, strpos($_SERVER["REQUEST_URI"], "?"));
$location = "Location: {$protocol}{$_SERVER["HTTP_HOST"]}{$requesturi}";
} else {
$requesturi = $_SERVER["REQUEST_URI"];
$location = "Location: {$protocol}{$_SERVER["HTTP_HOST"]}{$requesturi}";
}
} else {
$location = "Location: {$protocol}{$_SERVER["HTTP_HOST"]}{$_SERVER['PHP_SELF']}";
}
if (!empty($query)) {
$location .= "?{$query}";
}
header($location);
exit;
}
回答by Jake
You shouldn't put more than two lines in URL address. Check you URL.
您不应该在 URL 地址中放置超过两行。检查你的网址。
Good URL - "http://mail.google.com" - 1 line
Bad URL - "http://mail. - 2 lines
google.com/"
回答by CPTNnimo
Trouble could be in your phpMyAdmin, table wp_options, option_value.
问题可能出在您的 phpMyAdmin、表 wp_options、option_value 中。
If there is a spacebefore the URL it will generate the ERROR: warning: header may not contain more than a single header, new line detected in...
如果URL 前有空格,它将生成错误:警告:标头可能不包含多个标头,在...中检测到新行
回答by ITC ADU
This warning occurs to indicate that you might have a new line [/n] in the string content of your variables. Example
出现此警告表明您的变量的字符串内容中可能有一个新行 [/n]。例子
header("Location: ../control.php?post='$title1'&sample='$val'");
here there are 2 variables
这里有2个变量
$title1 and & $val
$title1 和 & $val
so while running if This warning occurs warning
所以在运行时如果出现此警告警告
“Header may not contain more than a single header, new line detected”
“标题不能包含多个标题,检测到新行”
The solution isTo strip out the passable new line contents of the variable Like this
解决办法是去掉变量的可通过的新行内容像这样
$val=str_replace(PHP_EOL, '', $val);
$title1=str_replace(PHP_EOL, '', $title1);
Then you can include the variables in the header
然后你可以在标题中包含变量
The ideal way of solving it is like this
理想的解决方法是这样的
$url="../control.php?post='$title1'&sample='$val'";
$url=str_replace(PHP_EOL, '', $url);
header("Location: $url");
** This will work 100%;**
** 这将 100% 有效;**
回答by raidenace
Seems like the variables you are using to create the Location attribute has a new line character in them. Pass them through urlencode()
似乎您用来创建 Location 属性的变量中有一个换行符。通过urlencode()传递它们
回答by karmafunk
Try encoding your URL and it should work : http://php.net/manual/en/function.urlencode.php
尝试对您的 URL 进行编码,它应该可以工作:http: //php.net/manual/en/function.urlencode.php
回答by Suresh G
You should put the URL "http://example.comlike this , please avoid "http://example.com/" "/" does give URL Mismatch , so avoid , Same problem will comes wordpress also. So try to use like this.
您应该像这样输入“ http://example.com” ,请避免“ http://example.com/”“/”确实会导致 URL 不匹配,因此请避免,wordpress 也会出现同样的问题。所以尝试使用像这样。