I want to use sessions to cover myself in case the user switches off cookies
so I am passing the session ID manually through a hidden input field. This
is what I have so far.
index.php page contains:
<?php
$_SESSION['entered_userna me'] = "";
$_SESSION['login'] = "";
$PHPSESSID = session_id();
echo "<form method='POST' action='login.p hp'>
<b>Username:</b>
<input type='text' name='username' >
<b>Password:</b>
<input type='password' name='password' >
<input type='hidden' name='PHPSESSID ' value='$PHPSESS ID'>
<input type='submit' value='Login'>
</form>";
?>
Now, viewing the source with this page open in the browser, I can see that
the session ID is in the hidden field. According to the book I'm reading,
"PHP will automatically get $PHPSESSID without anymore programming from you
on the login page"
The part of the next page (login.php) that is processing the login is as
follows:
if(mysql_num_ro ws($result) == 1)
{
$_SESSION['entered_userna me'] = $_POST['username'];
$_SESSION['login'] = 'yes';
header('refresh : 3; url=member.php' );
echo "<h2><center>Yo u have been validated. Please wait, logging you in. .
..</h2><br>
<center>If your browser doesn't support redirection and you're still here in
3 seconds, <a href='member.ph p'>click here</a></center>";
}
else
{
header('refresh : 5; url=index.php') ;
echo "<b><u><center> Login failure </b></u><br>Username/Password mismatch.
Sit tight, we're sending you back to the login page in 5 seconds.<br>
If your browser doesn't support redirection and you're still here in 5
seconds, <a href='index.php '>click here</a></center>";
}
Now we get to the member.php page and the following happens:
Notice: Undefined index: login in C:\Web\member.p hp on line 10
Line 10 reads:
if ($_SESSION['login'] != 'yes')
{
echo "<b><u><center> You haven't logged on!</b></u><p>
<a href='index.php '>Click Here</a> to return to the login page";
exit();
}
This is where it kicks me out. The code on the member.php page is designed
to stop users doing anything before they log in but unless I can pass the
session data between pages, the result of the if statement will always be
false.
Even more odd is the fact that it works in Internet Explorer and not
Mozilla. Now I trust Mozilla's standards far more than IE so I really want
to make it work in Mozilla.
Sorry this is such a long post, I tried to keep it as short as possible but
give enough information to make it make sense.
So what am I missing? And what is IE doing that Moz isn't?
Thanks for any suggestions.
so I am passing the session ID manually through a hidden input field. This
is what I have so far.
index.php page contains:
<?php
$_SESSION['entered_userna me'] = "";
$_SESSION['login'] = "";
$PHPSESSID = session_id();
echo "<form method='POST' action='login.p hp'>
<b>Username:</b>
<input type='text' name='username' >
<b>Password:</b>
<input type='password' name='password' >
<input type='hidden' name='PHPSESSID ' value='$PHPSESS ID'>
<input type='submit' value='Login'>
</form>";
?>
Now, viewing the source with this page open in the browser, I can see that
the session ID is in the hidden field. According to the book I'm reading,
"PHP will automatically get $PHPSESSID without anymore programming from you
on the login page"
The part of the next page (login.php) that is processing the login is as
follows:
if(mysql_num_ro ws($result) == 1)
{
$_SESSION['entered_userna me'] = $_POST['username'];
$_SESSION['login'] = 'yes';
header('refresh : 3; url=member.php' );
echo "<h2><center>Yo u have been validated. Please wait, logging you in. .
..</h2><br>
<center>If your browser doesn't support redirection and you're still here in
3 seconds, <a href='member.ph p'>click here</a></center>";
}
else
{
header('refresh : 5; url=index.php') ;
echo "<b><u><center> Login failure </b></u><br>Username/Password mismatch.
Sit tight, we're sending you back to the login page in 5 seconds.<br>
If your browser doesn't support redirection and you're still here in 5
seconds, <a href='index.php '>click here</a></center>";
}
Now we get to the member.php page and the following happens:
Notice: Undefined index: login in C:\Web\member.p hp on line 10
Line 10 reads:
if ($_SESSION['login'] != 'yes')
{
echo "<b><u><center> You haven't logged on!</b></u><p>
<a href='index.php '>Click Here</a> to return to the login page";
exit();
}
This is where it kicks me out. The code on the member.php page is designed
to stop users doing anything before they log in but unless I can pass the
session data between pages, the result of the if statement will always be
false.
Even more odd is the fact that it works in Internet Explorer and not
Mozilla. Now I trust Mozilla's standards far more than IE so I really want
to make it work in Mozilla.
Sorry this is such a long post, I tried to keep it as short as possible but
give enough information to make it make sense.
So what am I missing? And what is IE doing that Moz isn't?
Thanks for any suggestions.
Comment