CakePHP错误:无法配置会话,设置session.auto_start失败

时间:2022-10-20 15:57:14

I'm getting this error:

我收到这个错误:

Error: [CakeSessionException] Unable to configure the session, setting session.auto_start failed.

错误:[CakeSessionException]无法配置会话,设置session.auto_start失败。

I'm using Cakephp 2.2.4.

我正在使用Cakephp 2.2.4。

EDIT

编辑

It seems this guy had the same issue: Cakephp Session error on live site and using this

看起来这个人有同样的问题:在现场网站上使用Cakephp Session错误并使用它

if(!isset($_SESSION)) session_start(); 

inside beforefilter method of AppController fix the error.

在AppController的beforefilter方法中修复错误。

So my question is: why this happened? Everything was working fine and then suddendly this error appeared. Additionally I've realized that the folder app/tmp/sessions is empty and I have configured the session to be handled by Cake (in Config/core.php).

所以我的问题是:为什么会这样?一切都工作正常,然后突然出现这个错误。另外我已经意识到文件夹app / tmp / sessions是空的,我已将会话配置为由Cake处理(在Config / core.php中)。

5 个解决方案

#1


20  

In PHP version 5.4.19 - developers closed the ability to set session.auto_start option from user script.

在PHP版本5.4.19中 - 开发人员关闭了从用户脚本设置session.auto_start选项的功能。

CakePHP removed this option from default session configuration only in 2.4.0 version.

CakePHP仅在2.4.0版本中从默认会话配置中删除了此选项。

So you have 3 main option: upgrade CakePHP, downgrade PHP, or use standard php session.

所以你有3个主要选项:升级CakePHP,降级PHP或使用标准的php会话。

#2


24  

Andriy Struk's answer is correct. He said: So you have 3 main options: upgrade CakePHP, downgrade PHP, or use standard PHP sessions.

Andriy Struk的回答是正确的。他说:所以你有3个主要选择:升级CakePHP,降级PHP或使用标准的PHP会话。

But there's a 4th option, you can simply comment out a single line in /lib/Cake/Model/Datasource/CakeSession.php (around line 557):

但是有第四个选项,你可以简单地在/lib/Cake/Model/Datasource/CakeSession.php中注释掉一行(第557行左右):

// 'session.auto_start' => 0,

That stops Cake calling ini_set() on that setting, and prevents the fatal error.

这会阻止Cake在该设置上调用ini_set(),并防止致命错误。

#3


8  

As Andriy's answer says, you should upgrade CakePHP or downgrade PHP. However, if you don't want to or don't have the option to, you need to reconfigure your Cake session so that it uses standard PHP sessions rather than Cake's session.

正如Andriy的回答所说,你应该升级CakePHP或降级PHP。但是,如果您不想或不想选择,则需要重新配置Cake会话,以便它使用标准的PHP会话而不是Cake的会话。

app/Config/core.php

应用程序/配置/ core.php中

Configure::write('Session', array(
    'defaults' => 'cake', // You need to change the value of this to 'php'
    'timeout' => 120,
    'cookieTimeout' => 20160,
    'checkAgent' => false 
));

#4


5  

In your php.ini file, try setting session.auto_start to 1.

在php.ini文件中,尝试将session.auto_start设置为1。

#5


0  

as I do not have enough reputation to comment, I'm adding the following answer in addition to Simon's one:

因为我没有足够的声誉来评论,除了西蒙的一个,我还添加了以下答案:

to get it working, I had to comment out all three occurrences of 'session.auto_start' => 0 (around and after line 557 in CakeSession.php)

为了让它工作,我不得不注释掉'session.auto_start'=> 0的所有三次出现(在CakeSession.php的第557行左右)

For details, see the following patch of the CakePHP team: https://github.com/cakephp/cakephp/commit/faa2cbd3c3fc1bbf83064727847789123110b8e3#diff-bd8dc176fa0f41743dbaafa75f77b5ae

有关详细信息,请参阅CakePHP的团队下面的补丁:https://github.com/cakephp/cakephp/commit/faa2cbd3c3fc1bbf83064727847789123110b8e3#diff-bd8dc176fa0f41743dbaafa75f77b5ae

#1


20  

In PHP version 5.4.19 - developers closed the ability to set session.auto_start option from user script.

在PHP版本5.4.19中 - 开发人员关闭了从用户脚本设置session.auto_start选项的功能。

CakePHP removed this option from default session configuration only in 2.4.0 version.

CakePHP仅在2.4.0版本中从默认会话配置中删除了此选项。

So you have 3 main option: upgrade CakePHP, downgrade PHP, or use standard php session.

所以你有3个主要选项:升级CakePHP,降级PHP或使用标准的php会话。

#2


24  

Andriy Struk's answer is correct. He said: So you have 3 main options: upgrade CakePHP, downgrade PHP, or use standard PHP sessions.

Andriy Struk的回答是正确的。他说:所以你有3个主要选择:升级CakePHP,降级PHP或使用标准的PHP会话。

But there's a 4th option, you can simply comment out a single line in /lib/Cake/Model/Datasource/CakeSession.php (around line 557):

但是有第四个选项,你可以简单地在/lib/Cake/Model/Datasource/CakeSession.php中注释掉一行(第557行左右):

// 'session.auto_start' => 0,

That stops Cake calling ini_set() on that setting, and prevents the fatal error.

这会阻止Cake在该设置上调用ini_set(),并防止致命错误。

#3


8  

As Andriy's answer says, you should upgrade CakePHP or downgrade PHP. However, if you don't want to or don't have the option to, you need to reconfigure your Cake session so that it uses standard PHP sessions rather than Cake's session.

正如Andriy的回答所说,你应该升级CakePHP或降级PHP。但是,如果您不想或不想选择,则需要重新配置Cake会话,以便它使用标准的PHP会话而不是Cake的会话。

app/Config/core.php

应用程序/配置/ core.php中

Configure::write('Session', array(
    'defaults' => 'cake', // You need to change the value of this to 'php'
    'timeout' => 120,
    'cookieTimeout' => 20160,
    'checkAgent' => false 
));

#4


5  

In your php.ini file, try setting session.auto_start to 1.

在php.ini文件中,尝试将session.auto_start设置为1。

#5


0  

as I do not have enough reputation to comment, I'm adding the following answer in addition to Simon's one:

因为我没有足够的声誉来评论,除了西蒙的一个,我还添加了以下答案:

to get it working, I had to comment out all three occurrences of 'session.auto_start' => 0 (around and after line 557 in CakeSession.php)

为了让它工作,我不得不注释掉'session.auto_start'=> 0的所有三次出现(在CakeSession.php的第557行左右)

For details, see the following patch of the CakePHP team: https://github.com/cakephp/cakephp/commit/faa2cbd3c3fc1bbf83064727847789123110b8e3#diff-bd8dc176fa0f41743dbaafa75f77b5ae

有关详细信息,请参阅CakePHP的团队下面的补丁:https://github.com/cakephp/cakephp/commit/faa2cbd3c3fc1bbf83064727847789123110b8e3#diff-bd8dc176fa0f41743dbaafa75f77b5ae