note 40031 added to function.session-start
| From: | php-general at lists dot php dot net | Date: | Thu, 19 Feb 2004 13:26:20 +0000 |
| Subject: | note 40031 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65380@lists.php.net to get a copy of this message | ||
Due to an upgrade of my PHP version to 4.3.3, I encountered some problems with my session.
In fact, I dont understand why my sessions were lost at an untimely moment.
Ive 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 !
----
Manual Page -- http://www.php.net/manual/en/function.session-start.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40031
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40031&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40031&report=yes
Search -- http://master.php.net/manage/user-notes.php