I have a 3 pages to authenticate users against saved info in mysql databse, files are named:
form.htm
validate.php
verify_login.php
I'm able to deal with sessoin variables in validate.php but can't pass the to next page; verify_login.php. I get the eror msg eventhough the session id does not change.
Anyone can help?
regards.
form.htm
-----------
<form action="validate.php" method="post">
<table width="50%" border="0" align="center" cellpadding="4" cellspacing="0">
<tr>
<td width="22%">Username:</td>
<td width="78%"><input name="user_name" type="text"></td>
</tr>
<tr>
<td>Password:</td>
<td><input name="password" type="password"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
validate.php
--------------
<?php
// start the session
session_start();
header("Cache-control: private"); //IE 6 Fix
// Get the user's input from the form
$user_name = $_POST['user_name'];
$password = $_POST['password'];
$password= md5($password);
$db_user ="myusername";
$db_pass ="mypassword";
$connection = mysql_connect( 'localhost', $db_user, $db_pass );
mysql_select_db('mydatabas
e', $connection);
$query ="select * from users where username='$user_name' and PASSWORD='$password'";
$result = mysql_query($query, $connection);
$affected_rows = mysql_num_rows($result);
if ($affected_rows==1) :
print "validated <br>";
echo session_id();
$_SESSION['user_name'] = $user_name;
if (isset($_SESSION['user_nam
e'])) {
echo "<br>session variable is set and has the value:".$_SESSION['user_na
me'];
}
echo "<br><a href=\"verify_login.php\">
verify login</a>";
else :
print "not validated";
endif;
?>
verify_login.php
------------------
<?php
SESSION_START();
if (!isset($_SESSION['user_na
me'])) :
echo "error: not loged in or session expired.";
echo "<br>". session_id();
else:
echo "sucessfuly verified ligin on another page";
echo "<br>". session_id();
endif;
?>
Start Free Trial