SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2011
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to check if session is already started?

    Hi,

    I'm using session_start() to initiate the session and then assign a value in session global variable. But sometimes I get an error on session_start() saying session is already started. So is there a way to check if session is already started or not to get rid of such errors?

    Also please suggest if there is any better way rather than checking existances of session.

    Thanks!

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    when you start the session for the first time, set a session variable and it could be anything.
    eg.... $mySessVar = 'qwerty';

    Then when you want to check if a session is runing, simply check for the existance and value of $mySessVar.

    PHP Code:
    if(isset($mySessVar) && $mySessVar == 'qwerty'){
              
    //session is running
    } else {
             
    //session is not running



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •