framework icon indicating copy to clipboard operation
framework copied to clipboard

Possible [Bug] with Session's lifetime ( and Auth )

Open devmach opened this issue 13 years ago • 3 comments

According to session's config file , if i set lifetime parameter to 0 session should expire after browser closes. But it doesn't, it expires immediately. If i set lifetime to something like 30 mins, session class works as expected ( I tried cookie and database drivers ) .

The problem affects Auth class to and it makes impossible to for user to authenticate. Either session class should be some fixed or the config comment.


I'm using nginx and php-fpm under ubuntu 12.10 and testing using latest chrome ( Version 24.0.1312.52 m ). And if it matters my test server uses UTC as a timezone.

www-data@jagger:~$ php -v PHP 5.4.6-1ubuntu1.1 (cli) (built: Nov 15 2012 01:18:34) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

www-data@jagger:~/jagger$ date Mon Jan 21 03:12:20 UTC 2013

www-data@jagger:~/jagger$ php ../composer.phar show|grep laravel/framework laravel/framework [dev-master f11b8db] : The Laravel Framework.

devmach avatar Jan 21 '13 03:01 devmach

Confirmed. https://github.com/laravel/framework/blob/master/src/Illuminate/Session/Store.php#L158 always returns true if $lifetime is set to 0. There's some other uses of $lifetime in that file which might be problematic as well.

alexwhitman avatar Jan 21 '13 09:01 alexwhitman

Thanx @alexwhitman , i couldn't pinpoint root of the problem.

It looks like it's fairly normal because if lifetime is equal to 0 , multiplication will return 0 and time()-$session['last_activity'] will be always greater than.

I fixed the code as follows and session class is working now as expected. I'm not able to send a pull reuqest right now but i'll do it when i'm at home.

    return ( $this->lifetime === 0 
                    ? false 
                    : (time() - $session['last_activity']) > ($this->lifetime * 60) 
            );

Edit : I created a pull request , please check #111

devmach avatar Jan 21 '13 14:01 devmach

Fixed.

taylorotwell avatar Jan 23 '13 03:01 taylorotwell