Magento Session Problems

There are a number of session problems in Magento – just look around the web and you’ll see examples of people having trouble with cookie lifetimes, folder/file permissions and lot’s of other various tweaks and changes. All of these problems have answers, our recent problem however did not have an answer at all.

Our problem was the fact that our clients Magento website was not adding any products to cart, nor allowing you to login to the admin. In fact when we looked at the var/session folder – nothing was being written to it at all!

All symptoms pointed toward the common problems – cookies / folder permissions. This was not out issue.

Our issue revolved around line 44-46 of app/code/core/Mage/Core/Model/Session/Abstract/Varien.php exactly these lines of code:

if (isset($_SESSION)) {
    return $this;
}

These lines of code appear within the start() function – essentially telling Magento not to carry on setting up it’s session variables if there is already a session in place.

We found that within our index.php was an included file that somehow started another session – therefore telling Magento not to bother (not to bother calling session_start()) – this led to the website displaying correctly, but no ability to add products to cart or login to the admin – nor any error message!

To fix this all we had to do was to add the following line to index.php below where we were including our custom file and above where Magento was being called.

require_once('some/dodgy/session/starting/file.php');
unset($_SESSION);

That was it, that’s all we had to fix. What a headache – and a reminder not to hack your Magento website in too many ways as debugging an issue like this takes hours.

  • Archana

    Hello,

    I am facing exactly this issue. session folder remains blank.

    http://magento.stackexchange.com/questions/5396/session-gets-clear-in-category-page-only-in-magento

    Please give me solution.

    • Rob Kent

      Hi Archana,

      First things to check:

      1. make sure your var folder is writable by the server
      2. make sure the individual folders within that are writable

      Next things – as in this particular case:

      1. perform a var_dump($_SESSION); above Mage::run() in your index.php file
      – if something is stored then do the unset($_SESSION) before your Mage::run

      If those 2 don’t fix it then check your server error logs to see if there’s anything in there that can narrow it down

    • http://www.creare.co.uk/ Robert Kent

      First things to check:

      1. make sure your var folder is writable by the server

      2. make sure the individual folders within that are writable

      Next things – as in this particular case:

      1. perform a var_dump($_SESSION); above Mage::run() in your index.php file

      – if something is stored then do the unset($_SESSION) before your Mage::run

      If those 2 don’t fix it then check your server error logs to see if there’s anything in there that can narrow it down

  • jcalagaz

    This problem describes an issue I am having with magento, however my issue only starts when I change the store URL from what I installed it as to the live URL
    I am not a programmer but am pretty good at following directions. I have opened up my index.php but I do not know what to look for or where to put the line of code about the sessions.
    thanks
    Joe