Jump to content

How To Redirect Back And Reload Session Value


baijiazi
 Share

Recommended Posts

Hi all, I have just started learning PHP. I hit into this wall currently where I have a page(main.php) which stores the session value 'name' of the login personnel.On login to main.php, some sql scripts will run and username and some values will be shown on the page. The page also allows user to input some values and on submit, the value will be send to confirm.php to validate. So on confirm.php, I have this small code

 if ($tday < $day){		  		  if($tmth <= $mth){					  echo "Please select a valid Date!!";			  header("Refresh: 3; url=http://localhost/main.php");}		  else{			  $tempDay = cal_days_in_month(0,$mth,$yr);			  $tempTotal = $tday + ($tempDay-$day);			  $calDays = $tempTotal + 1;			  echo "Total Number of Days Taken is ".$calDays;		  }   }

This line

header("Refresh: 3; url=http://localhost/main.php");

will redirect back to the previous page automatically after 3 seconds.but I find that the session value 'name' is not loaded. anyway i can change it to reload the whole main.php? TIABai

Link to comment
Share on other sites

i am not sure what do you mean byy raloading whole main.php .did you started session_start() in that page where you want to pull data of session?

Link to comment
Share on other sites

Hi, Sorry abt it think I found my problem.

$_SESSION['name'] = $_POST['fname'];

think the page also reloaded this and as fname is empty, the session name is also empty. I put an if statement in front to do a check if fname have value before assigning it to session name and it work. Thanks for the reply.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...