note 92541 added to function.session-set-cookie-params

From: Date: Tue, 28 Jul 2009 20:13:37 +0000
Subject: note 92541 added to function.session-set-cookie-params
Groups: php.notes 
Request: Send a blank email to php-notes+get-158843@lists.php.net to get a copy of this message
I've found session_set_cookie_params to be ineffective at changing the session lifetime, to change the session lifetime I do the following: <?php $Lifetime = 3600; $Seperator = (strstr(strtoupper(substr(PHP_OS, 0, 3)), "WIN")) ? "\\" : "/"; $DirectoryPath = dirname(__FILE__) . "{$Seperator}SessionData"; is_dir($DirectoryPath) or mkdir($DirectoryPath, 0777); if (ini_get("session.use_trans_sid") == true) { ini_set("url_rewriter.tags", ""); ini_set("session.use_trans_sid", false); } ini_set("session.gc_maxlifetime", $Lifetime); ini_set("session.gc_divisor", "1"); ini_set("session.gc_probability", "1"); ini_set("session.cookie_lifetime", "0"); ini_set("session.save_path", $DirectoryPath); session_start(); ?> I switched to this after having many failed attempts at having a session remain active for longer than the default 24 minutes, the problem it seems is what many suggest that appears to be wrong - Setting the cookie lifetime to be the same as session.gc_maxlifetime, although the expiry of the cookie is set, it isn't updated when the user remains active in the session, so even if the session is actively being used, once the cookie life runs out, the sessions gets invalidated, using the above seems to work for me. ---- Server IP: 87.124.35.190 Probable Submitter: 86.0.109.1 ---- Manual Page -- http://www.php.net/manual/en/function.session-set-cookie-params.php Edit -- https://master.php.net/note/edit/92541 Del: integrated -- https://master.php.net/note/delete/92541/integrated Del: useless -- https://master.php.net/note/delete/92541/useless Del: bad code -- https://master.php.net/note/delete/92541/bad+code Del: spam -- https://master.php.net/note/delete/92541/spam Del: non-english -- https://master.php.net/note/delete/92541/non-english Del: in docs -- https://master.php.net/note/delete/92541/in+docs Del: other reasons-- https://master.php.net/note/delete/92541 Reject -- https://master.php.net/note/reject/92541 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158843) next »