note 71498 added to function.session-destroy
| From: | roba dot t dot mobiusd dot o dot t dot ph at osu1 dot php dot net | Date: | Sat, 02 Dec 2006 10:02:57 +0000 |
| Subject: | note 71498 added to function.session-destroy | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120228@lists.php.net to get a copy of this message | ||
I was experiencing problems with "sess_deleted" files and tracked it down to:
setcookie(session_name(), '', time()-42000, '/');
When "setcookie" is passed an empty value (ie, ''), it changes the value to the
string "deleted" and sets the date to exactly one year and one second in the past,
ignoring the expiration parameter.*
So, I'm guessing that if a client machine has its time set to more than a year in the past or
if the browser is somehow broken, then a site visitor could potentially send a PHPSESSID with a
value of "deleted". This will cause PHP to create a "sess_deleted" file in the
sessions directory.
In my case, I was seeing several incidents per minute, with each user clobbering the other's
session data causing all kinds of security and identity issues. Two changes seemed to have solved
the problem:
1) Use session_id() in place of '' in setcookie, as well as pick a date that's far in
the past (in this case Jan 1, 1970, 8:00:01AM):
setcookie(session_name(), session_id(), 1, '/');
2) Use session_regenerate_id() when logging a user in or otherwise changing their authority level.
Hope this helps somebody.
Rob
* Here is the relevant code in head.c:
if (value && value_len == 0) {
/*
* MSIE doesn't delete a cookie when you set it to a null value
* so in order to force cookies to be deleted, even on MSIE, we
* pick an expiry date 1 year and 1 second in the past
*/
time_t t = time(NULL) - 31536001;
dt = php_format_date("D, d-M-Y H:i:s T", sizeof("D, d-M-Y H:i:s T")-1,
t, 0 TSRMLS_CC);
sprintf(cookie, "Set-Cookie: %s=deleted; expires=%s", name, dt);
----
Server IP: 66.163.161.117
Probable Submitter: 203.177.221.135
----
Manual Page -- http://www.php.net/manual/en/function.session-destroy.php
Edit -- https://master.php.net/note/edit/71498
Del: integrated -- https://master.php.net/note/delete/71498/integrated
Del: useless -- https://master.php.net/note/delete/71498/useless
Del: bad code -- https://master.php.net/note/delete/71498/bad+code
Del: spam -- https://master.php.net/note/delete/71498/spam
Del: non-english -- https://master.php.net/note/delete/71498/non-english
Del: in docs -- https://master.php.net/note/delete/71498/in+docs
Del: other reasons-- https://master.php.net/note/delete/71498
Reject -- https://master.php.net/note/reject/71498
Search -- https://master.php.net/manage/user-notes.php