#16349 [Com]: no way to tell if a session exists without starting it

From: Date: Wed, 30 Aug 2006 07:50:49 +0000
Subject: #16349 [Com]: no way to tell if a session exists without starting it
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-101516@lists.php.net to get a copy of this message
ID: 16349 Comment by: stefan at stefankoopmanschap dot nl Reported By: adam at adeptsoftware dot com Status: Open Bug Type: Feature/Change Request Operating System: WinXP PHP Version: 4.1.2 New Comment: I have a similar issue. I pass the session ID in XML communication between a desktop application and my server. When a request comes in, I want to ensure that a session with the passed session id exists before I start it. It seems this is not possible at the moment. I am, by the way, using PHP5, not PHP4. An additional session_exists() feature would be great! Previous Comments: ------------------------------------------------------------------------ [2005-10-28 23:30:32] jon at fuck dot org it would be great to be able to get the correct session_id() before starting a session. currently, said function returns null if the session has not started yet, whether or not there is an existing one. the overhead of creating the session is the problem, though, so if doing so is still necessary in order to retrieve the id, then some other means -- i.e., a session_exists() function -- would be sufficient for cutting the overhead when managing ungodly amounts of sessions. ------------------------------------------------------------------------ [2005-10-28 23:21:20] david@php.net powerblade's comment is incorrect, the point of this bug is to determine whether the user has a session without creating a new one if they do not. (session_id always returns a blank string prior to session_start(), regardless of whether an actual session exists). Example: a site wishes to print "Hello <username>" at the top of every page. Username is stored on a session. The site must therefore resume the session to retrieve this username. But it is pointless to *create* a session just for this purpose. A bunch of useless 0-byte sess_* files are wastefully created. In Java, one would do request.getSession(false) - the parameter 'start' set to false causes this function to return null if no session already exists. In PHP, better semantics would be to add a function such as bool session_exists() This still needs to be addressed. ------------------------------------------------------------------------ [2002-12-03 15:37:01] powerblade at mail dot dk I had the same problem. I wanted to knew if the session was started or not. I found out i should do a session_id(); If it returns "null" then it's not started yet, else it returns the session id. ------------------------------------------------------------------------ [2002-04-14 16:17:06] adam at adeptsoftware dot com Why is this suspended? ------------------------------------------------------------------------ [2002-04-03 12:02:03] adam at adeptsoftware dot com Heh when I think bug I think "flaw", I don't consider basic functionality to be a feature. Knowing if a session has been created or not without having to create one seems pretty basic to me.. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/16349 -- Edit this bug report at http://bugs.php.net/?id=16349&edit=1

« previous php.bugs (#101516) next »