Jump to content

Recommended Posts

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;
}

Link to comment
https://forums.phpfreaks.com/topic/73278-sessions/
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/73278-sessions/#findComment-369733
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/73278-sessions/#findComment-369934
Share on other sites

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.