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;
}
in "Illuminate\Auth\Middleware\Authenticate" The method "redirectTo" should return an url path, not the Redirect response.
...
protected function redirectTo()
{
if(\Auth::user()->hasRole('copy')){
return '/copy/dashboardCopy';
}
}
...
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/"
This warning occurs to indicate that you might have a new line [/n] in the string content of your variables. Example
header("Location: ../control.php?post='$title1'&sample='$val'");
here there are 2 variables
$title1 and & $val
so while running if This warning occurs warning
“Header may not contain more than a single header, new line detected”
The solution is To 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%;**
Trouble could be in your phpMyAdmin, table wp_options, option_value.
If there is a space before the URL it will generate the ERROR: warning: header may not contain more than a single header, new line detected in...
Seems like the variables you are using to create the Location attribute has a new line character in them. Pass them through urlencode()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With