ShaolinF Posted October 15, 2007 Share Posted October 15, 2007 Hi Guys, I am trying to temp save some data(username, dob, phone, email) of a user when he types it into the form. When the form is submitted the data is utilised properly on the next page. But when I close the browser and reopen it (session would have been lost by now) and go back to the same page, it should redirect me back to the form as there is no session but it doesnt. But if I go to the main form and try to enter data into form to continue, it will keep reloading the form. See code below: if (!isset($_SESSION['LOGGEDIN'])) { $_SESSION['LOGGEDIN'] = TRUE; $_SESSION['NAME'] = $_POST['name']; $_SESSION['CONTACTNO'] = $_POST['contact']; $_SESSION['EMAILADD'] = $_POST['email']; $_SESSION['GENDER'] = $_POST['sex']; } //should redirect me back to form if no session if ($_SESSION['LOGGEDIN'] == FALSE) { if (!headers_sent()) { header("Location: index.htm"); } exit; } Quote Link to comment https://forums.phpfreaks.com/topic/73278-sessions/ Share on other sites More sharing options...
MasterACE14 Posted October 15, 2007 Share Posted October 15, 2007 I believe you have 2 parts of the code the wrong way around. this part: <?php if (!isset($_SESSION['LOGGEDIN'])) and this part: <?php if ($_SESSION['LOGGEDIN'] == FALSE) the first part you are checking if the session "has NOT been set". So remove the exclamation mark so that line will look like this: if (isset($_SESSION['LOGGEDIN'])) and the second part of code, is checking if the session "HAS been set", so you need the isset function in their, and the exclamation mark, and a 'else' before the 'if' should hopefully stop the page from reloading. so your line should now look like this: <?php elseif (!isset($_SESSION['LOGGEDIN']) == FALSE) That should hopefully fix it. Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/73278-sessions/#findComment-369733 Share on other sites More sharing options...
ShaolinF Posted October 15, 2007 Author Share Posted October 15, 2007 Hi, Thanks, I made the changes but now the fields don't populate either. I'm REALLY confused at the moment as this is my first time doing such things, and in need of some major help, if you guys could help me with the IF statements because Ive been wrestling with them for hours to no avail. The first condition is, IF the user has entered his details on the form, he will be redirected to the confirm page, where the details he entered will be displayed and he will have the ability to change them if they are wrong. The second condition is, IF someone tries to access the confirm page and they have no session, they will be redirected back to the form. The third condition is, IF someone already has a session but then re-does the form and submits his new session should overwrite his older session. If some could give me a hand with these IF statements I would be very grateful. Quote Link to comment https://forums.phpfreaks.com/topic/73278-sessions/#findComment-369934 Share on other sites More sharing options...
ShaolinF Posted October 15, 2007 Author Share Posted October 15, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/73278-sessions/#findComment-370065 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.