note 40031 deleted from function.session-start by nlopess

From: Date: Thu, 19 Feb 2004 13:39:08 +0000
Subject: note 40031 deleted from function.session-start by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65387@lists.php.net to get a copy of this message
Note Submitter: ---- Due to an upgrade of my PHP version to 4.3.3, I encountered some problems with my session. In fact, I don’t understand why my sessions were lost at an untimely moment. I’ve tested this code, assuming $_SESSION[user_name] was previously defined : /* example start */ session_start(); // check to see if session exists // assumes $_SESSION[user_name] was previously defined by your custom login validation code switch (isset($_SESSION[user_name])) { case TRUE: // Client cookie was probably created. echo 'Session verified.'; break; case FALSE: // Client cookie either doesn't exist or wasn't created. // Browser privacy setting may be set too high. echo 'Verificiation FAILED!'; break; } /* example end */ To solve the problem I added this piece of code just before the : session_start(); $cookie_session = "phpsessid"; if (isset($HTTP_COOKIE_VARS[$cookie_session])) session_id($HTTP_COOKIE_VARS[$cookie_session]); session_start(); if (!isset($HTTP_COOKIE_VARS[$cookie_session])) setcookie($cookie_session, session_id(), time() + 60*60*10); // 10 hours Perhaps, it's not the best way to solve the problem... but it works for me !

« previous php.notes (#65387) next »