CakePHP Error: Unable to configure the session, setting session.auto_start failed
Asked Answered
O

6

21

I'm getting this error:

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

I'm using Cakephp 2.2.4.

EDIT

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

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

inside beforefilter method of AppController fix the error.

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).

Orontes answered 25/9, 2013 at 12:6 Comment(5)
Had this as well out of nowhere. Updating to latest version of Cake fixed it, seems they might have done some work on the session setting...Trembles
@Trembles Ok, I will try itOrontes
@Trembles Which version?Goodfornothing
@Goodfornothing the latest (2.4.2 right now)Orontes
Thank for this answer, i have cake that redirect to him self without stopping and browser break connection obviously. Fortunately with many exit('ciao'); starting from index.php i find that code break after call to session write, because i change PHP version on server.Fischer
M
23

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

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

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

Mytilene answered 21/10, 2013 at 12:54 Comment(1)
Upgrading CakePHP solved my issue. Million thanks for this answer :)Arabelle
R
28

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

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

// 'session.auto_start' => 0,

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

Roseanneroseate answered 28/1, 2014 at 0:18 Comment(4)
any drawbacks of this method of implementation?Waterrepellent
I have not found any as yet. I don't believe that it was ever possible to change this setting inside a script, it's just that since PHP version 5.4.19 it actually fails now, rather than silently doing nothing.Roseanneroseate
Worked for me but am wondering if this method has any limitations, are the sessions now vulnerable?Burroughs
No, there's no security or reliability issues with doing this. As my comment mentions above, I don't think this line has ever actually served any purpose. It previously failed silently but now throws an error on more recent versions of PHP.Roseanneroseate
M
23

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

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

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

Mytilene answered 21/10, 2013 at 12:54 Comment(1)
Upgrading CakePHP solved my issue. Million thanks for this answer :)Arabelle
G
9

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.

app/Config/core.php

Configure::write('Session', array(
    'defaults' => 'cake', // You need to change the value of this to 'php'
    'timeout' => 120,
    'cookieTimeout' => 20160,
    'checkAgent' => false 
));
Goodfornothing answered 29/9, 2013 at 21:35 Comment(1)
Thanks. Yes, I'm using 1&1 shared hosting. I have to mail them I suppose.Orontes
E
7

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

Elkeelkhound answered 22/5, 2014 at 8:29 Comment(1)
Not an ideal solution, but definitely a valid fix.Ridgway
C
2

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)

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

Cleaner answered 5/3, 2015 at 14:24 Comment(0)
P
0

Find below code and comment all lines

/lib/Cake/Model/Datasource/CakeSession.php

if (empty($_SESSION) && !headers_sent() && (!function_exists('session_status') || session_status() !== PHP_SESSION_ACTIVE)) { if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) { foreach ($sessionConfig['ini'] as $setting => $value) { if (ini_set($setting, $value) === false) { throw new CakeSessionException(__d('cake_dev', 'Unable to configure the session, setting %s failed.', $setting)); } } } }

Presentational answered 15/9, 2022 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.