note 58165 deleted from function.session-start by betz

From: Date: Wed, 26 Oct 2005 14:19:35 +0000
Subject: note 58165 deleted from function.session-start by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-97622@lists.php.net to get a copy of this message
Note Submitter: jlh at gmx dot ch ---- 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(); } ?>

« previous php.notes (#97622) next »