Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The session id is too long or contains illegal characters in Laravel 4

I installed Laravel 4.0 and got this error

ErrorException SessionHandler::read(): The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' return (bool) $this->handler->close(); } /** * {@inheritdoc} / public function read($id) { return (string) $this->handler->read($id); } /*

like image 493
Gustavo Croquer Avatar asked May 29 '13 15:05

Gustavo Croquer


3 Answers

Do you have Laravel 3 installed on the same machine? By default, Laravel 4 uses the same session cookie name (as Laravel 3), now found in /app/config/session.php file. Simply change:

'cookie' => 'laravel_session',

to, e.g.

'cookie' => 'laravel_session_4',

and refresh browser. All should work now.

like image 76
Andrew U Avatar answered Oct 21 '22 17:10

Andrew U


It could be that you have a corrupt cookie. Try clearing cookies in your browser.

Take a look at this discussion: https://stackoverflow.com/a/16318456/1563189

Especially:

How do you end up with illegal characters in PHPSESSID in the first place? Aren't they generated by PHP automatically? – Lèse majesté Jul 6 '10 at 11:57

They are, but a cookie that links you to a generated session id is client side. If that cookie changes to an invalid format (somebody is trying to exploit something) PHP will notice it. – Aleksey Korzun Sep 6 '11 at 19:56

like image 22
Brian Avatar answered Oct 21 '22 18:10

Brian


There is a bug report for this problem (https://bugs.php.net/bug.php?id=68063)

You can check the success of your session_start and generate the id if needed:

$ok = @session_start();
if(!$ok){
session_regenerate_id(true); // replace the Session ID
session_start(); 
}
like image 27
alpere Avatar answered Oct 21 '22 19:10

alpere