Jump to content

Session variables


steonkeys

Recommended Posts

Hi,

 

I wonder if you could help me, as I can't see where I'm going wrong. I have got an area of my website that is password protected. tGateway.php gets the user to input the password then checks, then if it is correct, sets a session variable - $_SESSION['trainee'] = 1; and then redirects to another page. (tGPS.php) This works fine, the problem occurs when i then go from this page to any other page in the protected area. It kicks me out and takes me back to the password screen - as it is meant to do, if $_SESSION['trainee'] != '1'; So some how, the trainee variable it being reset to 0, I've done print variable on the tCP.php page without the if statement and it's claiming that the variable is 0. I can't see how it's reset it's self, and more the to the point how to stop it! There is not any other php code in the pages. See below for the php code of each page.

 

Thank you in advance.

 

Steven

 

 

tGateway.php (password form)

 

<?php session_start();

  if ($_POST['password'] == 'password') //not real password - I ain't that stupid  :P

  { $_SESSION['trainee'] = '1';

header("Location: http://www.gahp.co.uk/scitt/tGPS.php");

} ?>

 

tGPS.php (this one works fine - trainee is set to 1)

 

<?php session_start();

  if ($_SESSION['trainee'] != '1')

  {header("Location: http://www.gahp.co.uk/scitt/tGateway.php");

}

?>

 

tCP.php (this one doesn't work - trainee is some how set to 0 - but it shouldn't be)

 

<?php session_start();

  if ($_SESSION['trainee'] != '1')

  {header("Location: http://www.gahp.co.uk/scitt/tGateway.php");

}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/70613-session-variables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.