CakePHP 2.x sessions behaving inconsistently between local dev and production

柔情痞子 提交于 2019-11-29 08:53:44

In you app/Config/core.php check out these thing.

  1. If you are using SSL and non-SSL based protocols, make sure you have cookie_secure set as false.

    Configure::write('Session', array(
       'defaults' => 'php',
       'ini' => array(
           'session.cookie_secure' => false
       )
    ));
    
  2. Try changing Session's configuration from php defaults to cake or db as

    Configure::write('Session', array(
        'defaults' => 'php', // change 'php' to 'cake' or 'database'
        'cookie' => 'my_app',
        'timeout' => 4320 //3 days
    ));
    
  3. Also try setting Session.checkAgent to false, just for once to ensure if it is a browser issue.

  4. Try changing Session.name of your session, it defaults to 'CAKEPHP'

    Configure::write('Session', array(
        'name' => 'New-Session-name'
        'defaults' => 'php', // change 'php' to 'cake' or 'database'
        'cookie' => 'my_app',
        'timeout' => 4320 //3 days
    ));
    
  5. Remove all cache files from all sub-directories of /app/tmp

  6. Set debug level higher to 1, to do cache refresh. If you still don't see an error, try setting error_reporting to true in php.ini. (Although, this one is very obvious I am still pointing it out in case you might have missed it out)

Hope this helps

One of the recommendations I came across frequently was to ensure that there was no whitespace after the closing PHP tag in a code-only file (or preferably to not actually have a closing PHP tag). Checking all my files showed that to be the case. Somehow, however, I managed to put a single line break before the opening PHP tag in AppController.php and that was the issue. My apologies to anyone who wasted time on this. I just hope this helps someone in the future who clumsily makes the same mistake.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!