in reply to CGI error: "Invalid header value contains a newline not followed by whitespace"

$cookie does not contain a cookie or a reference to an array of cookies. It's garbage.
my $cookie = $cookie1."\nSet-Cookie: $cookie2"."\nSet-Cookie: $cookie3 +\nSet-Cookie: $cookie4";
should be
my $cookie = [ $cookie1, $cookie2, $cookie3, $cookie4 ];

Then we can clean up your code.

my @cookies; push @cookies, $cgi->cookie(-name => "login", -value => "", -expir +es => '-1d'); push @cookies, $cgi->cookie(-name => 'password', -value => "", -expir +es => '-1d'); push @cookies, $cgi->cookie(-name => 'id', -value => "", -expir +es => '-1d'); push @cookies, $cgi->cookie(-name => 'CGISESSID', -value => "", -expir +es => '-1d'); print $cgi->redirect( -cookie => \@cookies, -uri => $cgi->url(), );
or even
my @cookies = map { $cgi->cookie(-name => $_ -value => "", -expires => + '-1d') } qw( login password id CGISESSID ); print $cgi->redirect( -cookie => \@cookies, -uri => $cgi->url(), );

Replies are listed 'Best First'.
Re^2: CGI error: "Invalid header value contains a newline not followed by whitespace"
by groengoen (Initiate) on Oct 14, 2014 at 08:39 UTC
    Thanks very much for the very concise code. I used the last bit of code and it eliminated the error. However I actually wanted the logout to redirect to the calling url for the whole cgi. I am actually returned to the page with the logout tab(where I logged out). Any idea about that?

      Because you're passing the url of the page the user requested when you mean to redirect to the login page.

      Maybe $cgi->url(-base => 1) . '/login.html'?

        That worked perfectly, thanks very much.