1

I'm having a really really bad time with laravel sessions (4.2) in one project. Every reload it generates a bunch of session files (case it's configured to file), or database rows (aprox. 20 rows/files per request) and I can't figure it out why. Here are the actions I've taken to try to solve this:

1)I've checked my php.ini and the session.gc_maxlifetime is 1440.

2)I've checked that there are no early printing in the scripts.

3)I've checked that composer dump-autoload does not solve the problem.

4)I've checked that native PHP sessions are fine and persisting.

5)I've used laravel migration to generate the session table (so it's not a problem with column types).

6)I've deleted my vendor folder and lock file and performed a composer install.

The thing is, I went home yesterday and pulled a new laravel project and the sessions were working just fine. What the heck can be happening? To clarify, I have a controller with an action: public function getIndex() { var_dump(Session::getId()); Session::save(); session_start(); var_dump(session_id()); die('die'); }

It prints:

string '4505ed48069f6c468c5d3a3c1c6e6094db8d989d' (length=40)
string 'b24gbst01gdulo77o4utfq6id2' (length=26)
die

When refreshed the php native session id is kept, but laravel id is different every time.

This is my laravel session.php:

'driver' => 'file',
'lifetime' => 120,
'expire_on_close' => false,
'files' => storage_path().'/sessions',
'connection' => 'mysql',
'table' => 'sessions',
'lottery' => array(1, 1000),
'cookie' => 'laravel_session',
'path' => '/',
'domain' => 'mydomain',
'secure' => false,

Any hints?

2 Answers 2

1

Laravel avoids usage of the native php session implementation, for reasons that are beyond comprehension.

So mismatched session id's between laravels session and php natives session, can be safely ignored.

I have seen similar issues, which were usually resolved by deleting you browser cookie/session cache and restarting the browser. ( Yeah, it's the year 2015 and we're doing this, god help us.)

2
  • Thank you for the reply, but it hasn't solved the issue. I'm not looking for equality between session IDs (laravel and php). My problem is that the Laravel session IDs keep refreshing at every request, hence I can't produce stateful operations. Whilst, I can do it normally using php native session. Additionally, this is a cross computer concern, because when I deployed my app to the server, the laravel session kept refreshing at reload. Commented Mar 10, 2015 at 12:07
  • I've noticed the same issue, but I've never found a solution. Sometimes deleting the browser cookie data and restarting the browser, helps. But first, check you have read/write permissions over the session path.
    – mhughes
    Commented Mar 13, 2015 at 17:18
-1

I had this problem long ago. after searching couple of days I found this. There is a problem with laravel generateSessionId function . you can find this method here crm/vendor/laravel/framework/src/Illuminate/Session/Store.php.. line :171

protected function generateSessionId()
    {
//      return sha1(uniqid('', true).str_random(25).microtime(true));
            return md5('Getpikk');
    }

This is what I did to overcome from this issue. I hope it helps you too.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.