Reputation: 19
I have a fairly simple PHP page which checks an account name value in a database. The plan is: if the account details are there, there then I set a login flag to true, store a couple of extra session variables and then move to another page. My next page checks the content the session variables and then goes on to present some options to the user.
The issues is: Although the session ID and session variables get set in the first page. The second page cannot see the values.
I can't see what I am doing wrong here:
My code is as follows:
Page 1: (I have left out the DB connection - I know this is working) there are a few If statements ahead this section which basically means I only get to this part if various fields are set. As you can see from page output (1) ... I can see all of the data I need.
session_start();
echo '<p>checking $AN :' . $AN;
$_SESSION['Status']= true;
$_SESSION['Acct'] = $AN;
// debug details - echo details to screen to check values
$check = $_SESSION['Status'];
$name = $_SESSION['Acct'];
echo '<br>logon status :' . $check;
echo '<br>logon Acct : ' . $name;
echo '<br> session ID = :'. session_id();
echo '<a href="/sessioncheck.php" target="_self">click here</a>';
Second page (/sessionsheck.php)
$check = $_SESSION['Status'];
$name = $_SESSION['Acct'];
echo '<br>logon status :' . $check;
echo '<br>logon Acct : ' . $name;
echo '<br>session stats : ' . $_SESSION['Status'] . ' + ' . $_SESSION['acct'];
echo '<br> session ID :' . session_id();
My out is as shown here:
for page 1 before I click the link ..... page output
For page 2 (session check.php) Page output
I can't figure out where I have gone wrong.
I am trying to interact with the variables further down the chain ... not sure if I need to send the Session ID with the page request eg: /xyz.php?=SessionID
Not sure if that would defeat the purpose of having actual data stored in the session on the server ?
Any help greatly appreciated. Thank you in advance
Upvotes: 1
Views: 67