12

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); } /*

Rubens Mariuzzo
  • 28,358
  • 27
  • 121
  • 148
Gustavo Croquer
  • 121
  • 1
  • 1
  • 3
  • 2
    Do you have a Laravel 3 installation running locally as well. I do see this issue popping around around and it might be the case. Do note that both Laravel 3 and Laravel 4 using the same cookie name "laravel_session" by default. – crynobone May 30 '13 at 11:08

3 Answers3

44

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.

Andrew U
  • 739
  • 7
  • 10
11

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

Community
  • 1
  • 1
Brian
  • 697
  • 1
  • 7
  • 14
3

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(); 
}
alpere
  • 1,079
  • 17
  • 26
  • This worked for me, I think it's a more generic automatic fix for this kind of issues, however they happen. – fregante Feb 11 '15 at 15:42