note 58165 added to function.session-start
| From: | jlh at gmx dot ch | Date: | Wed, 26 Oct 2005 12:09:01 +0000 |
| Subject: | note 58165 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-97614@lists.php.net to get a copy of this message | ||
You may want to do the following: When suitable session data exists on the server, it shall be
loaded, but when not, no new session shall be created. This could be to avoid unnessary cookies to
be set and/or unnecessary sessions to lay around on the server (in worst cases, that would be one
for each and every visitor). Some people may not care about either reason, but some may.
The problem is that session_start() will create a new session when none exists. The following works
for me:
<?php
session_name('myname');
/* create a session anyway */
session_start();
if (/* is $_SESSION containing valid data? */)
{
/* yes, do my stuff here */
}
else
{
/* no, that session just got created; delete it again */
setcookie(session_name(), '', time() - 42000);
$_SESSION = array();
session_destroy();
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.session-start.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58165
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58165&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58165&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58165&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58165&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58165&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58165&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58165&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58165&report=yes
Search -- http://master.php.net/manage/user-notes.php