rward Posted May 3, 2007 Share Posted May 3, 2007 Hi, I am wondering if anybody can help here. basically what i want to do is at the start of my site check if the sessions are set and if not set them. My problem is that on calling the following snippet of code it processes the first time but does not actually assign the var 'session_id' until after a refresh or hitting the home page link that first calls this function. Which results further down the line as two entrys into my database first one blank and second one with the 'session_id' var correctly. if (!isset($_SESSION['session_id'])) { session_start(); $_SESSION['session_id'] = $PHPSESSID; ...save to database the variable session_id.... } Regards Rob Quote Link to comment Share on other sites More sharing options...
suzzane2020 Posted May 3, 2007 Share Posted May 3, 2007 place session_start at the very beginning of the script ..not in the condition Quote Link to comment Share on other sites More sharing options...
rward Posted May 3, 2007 Author Share Posted May 3, 2007 Yes I had tried this first and after different tests the condition was posted as previous but its the same effect. session_start(); if (!isset($_SESSION['session_id'])) { $_SESSION['session_id'] = $PHPSESSID; ...save to database the variable session_id.... } Quote Link to comment Share on other sites More sharing options...
scottybwoy Posted May 3, 2007 Share Posted May 3, 2007 Try $_SEESION['session_id'] = session_name(); Quote Link to comment Share on other sites More sharing options...
rward Posted May 3, 2007 Author Share Posted May 3, 2007 scottybwoy, This helps in the way that only one entry is saved to the DB until reloading the browser but the session ID itself is still not saved to the database or the variable 'session_id'. Could you elaborate on your answer. Cheers Rob Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.