php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17598 no way to detect a session without creating a session
Submitted: 2002-06-04 12:40 UTC Modified: 2002-08-11 01:45 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: adam at adeptsoftware dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.2.1 OS: WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: adam at adeptsoftware dot com
New email:
PHP Version: OS:

 

 [2002-06-04 12:40 UTC] adam at adeptsoftware dot com
There is no way to detect if a session exists, without creating a session.  This can trigger warnings like this in cookie detectors:

This page wishes to set the cookie
   PHPSESSID="bd977b12c9da97f1ba0b07e4fe25a176"

A page needs to generate differently based on whether a user is "logged in" (a session exists) or just a "visitor".

You shouldn't have to create a session to know if it exists.  I suppose you could manually check cookies & the URL etc but shouldn't there be a function for this?

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-05 09:00 UTC] postings dot dynweb at hans-spath dot de
// just a untested quick-hack
// if it doesn't work, I hope you get the idea

function session_exists( $name=NULL )
{
   if( $name === NULL )
      $name = ini_get('session.name');

   if( ini_get(session.use_cookies) == 1 )
      return isset($_COOKIE[$name]);
   else
      return isset($_GET[$name]);
}
 [2002-08-11 01:45 UTC] kalowsky@php.net
Sure there is, look at the nice patch provided by hans-spath.de!  Marking as bogus, as this isn't a bug.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC