I have the following script to create a session to authenticate users.
<?php
session_start();
$password = md5($password1);
// check correct values are passed
echo $password,"<br>",$username,"<br>",$custref,"<br>";
// Connecting, selecting database
$link = mysql_connect("localhost", "root")
or die("Could not connect");
mysql_select_db("testdb")
or die("Could not select database");
$sql = "Select * from access where custref='$custref' and username='$username' and password = '$password'";
// run SQL against the DB
$result = mysql_query($sql)
or die("access for this page has failed");
$myrow = mysql_fetch_array($result);
$admin = $myrow['admin'];
$user = $myrow['username'];
$pass = $myrow['password'];
$cref = $myrow['custref'];
echo $admin;
if ($POST['username']=$user && $POST['password']=$pass && $POST['custref']=$cref) {
$SESSION['auth_user']= $user;
$SESSION['auth_ref']= $cref;
$SESSION['auth_pass']= $pass;
$_SESSION['auth_admin']= $admin;
}
else
{
?>
<form method="post" action="login.php">
<b>Log into your account:</b><p>
<table width=100%>
<tr>
<td width=30%>Customer Reference:</td><td><input type="Text" name="custref" maxlength=20 value=""></td>
</tr>
<tr>
<td>Username:</td><td><input type="Text" name="username" maxlength=20 value=""></td>
</tr>
<tr>
<td>Password:</td><td><input type="password" maxlength=10 name="password1" value=""><td>
</tr>
</table>
<p>
<input type="Submit" name="submit" value="Enter">
</form>
<?php
}
?>
<form method="post" action="welcome.php?<?=SID?>">
<input type=submit value=submit>
</form>
It doesn't work and I can not work out why.
The form at the bottom is just to pass the session details to the next page where I am trying to echo the relevant variables to see it works.
Also, once it does work, what should I put at the top of my pages to determine if the user is looged in or not?
I have read as many tutorials as I can find on the web, but I am just getting more confused!
Please point me in the right direction.