收到警告"标头可能不包含多个标头,检测到新行"


getting warning "Header may not contain more than a single header, new line detected"

我正在做编码oops在PHP上传图像。但是在提交图片之后,它会给出警告

"标头不能包含多个标头,检测到新行"

下面是我的函数,它给出错误

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;
}

URL地址不能超过两行。检查你的URL

Good URL - "http://mail.google.com"  - 1 line
Bad URL - "http://mail.              - 2 lines
            google.com/"

in "Illuminate'Auth'Middleware'Authenticate"方法"redirectTo"应该返回一个url路径,而不是重定向响应。

...
protected function redirectTo()
{
    if('Auth::user()->hasRole('copy')){
        return '/copy/dashboardCopy';
    }       
}
...

出现此警告表示在变量的字符串内容中可能有一个新行[/n]。示例

  header("Location: ../control.php?post='$title1'&sample='$val'");

这里有两个变量

title1美元和,美元val

所以在运行时如果出现这个警告警告

"标头不能包含多个标头,检测到新行"

解决方案为删除变量中可通过的新行内容,如下所示

    $val=str_replace(PHP_EOL, '', $val);
    $title1=str_replace(PHP_EOL, '', $title1);

然后你可以在标题

中包含变量

理想的解决方法是这样的

$url="../control.php?post='$title1'&sample='$val'";
 $url=str_replace(PHP_EOL, '', $url);
 header("Location: $url");

麻烦可能在您的phpMyAdmin,表wp_options, option_value.

如果URL前有空格,它将生成ERROR: warning: header可能不包含多个header,新行检测到…

似乎您用于创建Location属性的变量中有一个新的行字符。通过urlencode()

传递它们

尝试编码您的URL,它应该工作:http://php.net/manual/en/function.urlencode.php

你应该把URL "http://example.com像这样,请避免"http://example.com/" "/"会给URL不匹配,所以避免,同样的问题也会出现在wordpress上。所以试着像这样使用

也许你需要添加路由

'middleware' => ['auth']

在你的routes/web.php

当我打算更改wp_options URL (siteurl和home)时,我在PhpmyAdmin中复制/粘贴我网站的URL时发生了这种情况。

我通过在wp_options中删除我的网站URL中的空白来解决它!