p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

  Return to Index  

beginning_php thread: Check for existence of a session

Message #1 by jazzsnob <jazzsnob@o...> on Wed, 23 Oct 2002 11:45:32 -0400
hello. i was wondering if anyone could help me on how to detect is a session
exists. i want to know this so i can log a new visitor into a database. i
need to detect to be sure the session doesn't exist first, then log, then
start the session and have it last until they close the browser... any


-----Original Message-----
From: Nikolai Devereaux [mailto:yomama@u...]
Sent: Monday, September 23, 2002 3:20 PM
To: beginning php
Subject: [beginning_php] RE: Complex MYSQL Query

The first (and probably easiest) thing to do is to switch to PostgreSQL --
pgsql offers transactions AND sub-selects.

If you're stuck with mysql, you can try using joins where possible, or break
each query separately and merge/filter the results by hand.

Without more details about the queries or the db schema, I can't really say
way or the other.


Message #2 by "Nikolai Devereaux" <yomama@u...> on Wed, 23 Oct 2002 09:46:23 -0700
well, you have to call session_start() each time you want a session enabled in
the page, even if it's to continue an existing session.

What I'd do is check for the existence of a particular variable.  Most people
use a simple "logged_in" type variable.


if(!isset($_SESSION['logged_in']) ||
    ($_SESSION['logged_in'] !== true)  )
    // first time here.
    // do all your session starting logging, etc.

    $_SESSION['logged_in'] = true;

// ...


take care,


  Return to Index