Jump to content

Best Way To Tell If Session Is Started


poddys

Recommended Posts

I inherited a system written in PHP where the originator was rather sloppy at coding, and where there are often errors but not consistent ones.

 

There are so many errors in the Apache log, I want to eradicate all of them, except for the "real" ones, as I currently can't see the wood for the trees...

 

One I have been trying to stop is where they added Session_start() at the beginning of every program, which of course generates a message if a session is already started.  I know it's a warning, but I "anally" would like to create code that does not generate warnings if at all possible.

 

What is the best way to determine if a session has already been started?  I have been using:

 

if (!isset ($_COOKIE[ini_get('session.name')]))

session_start();

 

but this doesn't always seem to work.

 

Thanks in advance for any help.

Tony

Link to comment
Share on other sites

if you exclude all session_start() calls and leave only the ones that get called directly, like the main screen, the things that get called through ajax or something. then you wouldn't need session_start() for the rest

I mean, included/required files don't need session_start()

 

other than that just check if session_id() returns an empty string

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.