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

匿名 (未验证) 提交于 2019-12-03 00:48:01

问题:

I am doing coding in oops for uploading image in PHP. But After submit image, it's giving warning

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

回答1:

You shouldn't put more than two lines in URL address. Check you URL.

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


回答2:

Seems like the variables you are using to create the Location attribute has a new line character in them. Pass them through urlencode()



回答3:

Try encoding your URL and it should work : http://php.net/manual/en/function.urlencode.php



回答4:

You should put the URL "http://example.com like this , please avoid "http://example.com/" "/" does give URL Mismatch , so avoid , Same problem will comes wordpress also. So try to use like this.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!