Laravel 4 中的会话 ID 太长或包含非法字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16817635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:49:50  来源:igfitidea点击:

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

installationlaravellaravel-4

提问by Gustavo Croquer

I installed Laravel 4.0 and got this error

我安装了 Laravel 4.0 并收到此错误

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

ErrorException SessionHandler::read(): session id 太长或包含非法字符,有效字符为 az, AZ, 0-9 和 '-,' return (bool) $this->handler->close(); } /** * {@inheritdoc} / public function read($id) { return (string) $this->handler->read($id); } /*

回答by Andrew U

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:

你在同一台机器上安装了 Laravel 3 吗?默认情况下,Laravel 4 使用相同的会话 cookie 名称(与 Laravel 3 相同),现在可以在 /app/config/session.php 文件中找到。只需更改:

'cookie' => 'laravel_session',

to, e.g.

例如

'cookie' => 'laravel_session_4',

and refresh browser. All should work now.

并刷新浏览器。现在一切都应该工作了。

回答by Brian

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

可能是您的 cookie 已损坏。尝试清除浏览器中的 cookie。

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

看看这个讨论: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 KorzunSep 6 '11 at 19:56

首先你是如何在 PHPSESSID 中得到非法字符的?它们不是由 PHP 自动生成的吗?– Lèse majesté10年7 月 6 日,11:57

它们是,但是将您链接到生成的会话 ID 的 cookie 是客户端。如果该 cookie 更改为无效格式(有人试图利用某些内容),PHP 会注意到它。– Aleksey Korzun2011年9 月 6 日 19:56

回答by alpere

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

这个问题有一个错误报告(https://bugs.php.net/bug.php?id=68063

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

您可以检查 session_start 是否成功并在需要时生成 id:

$ok = @session_start();
if(!$ok){
session_regenerate_id(true); // replace the Session ID
session_start(); 
}