Hi, i have the following script which allows users to log in (via a form on a previous page), this works perfectly fine but how can i stop users from accessing an htm page directly without logging on?
Here is my validation code...
<?
/* Check User Script */
include 'db.php';
// Convert to simple variables
$serialnumber = $_POST['serialnumber'];
$password = $_POST['password'];
if((!$serialnumber) || (!$password)){
//if either or both fields are null then go back to userlogin.htm
include 'userlogin.htm';
exit();
}
// check if the user info validates the db
$sql = mysql_query("select * from users where serialnumber='$serialnumber' and password='$password'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
//if the login is correct then set the cookie
$cookie_val=crypt($serialnumber);
//set the cookie so it dies when the browser is closed
setcookie ("this_cookie", $cookie_val, 0);
print($cookie_val);
//goto relevent page
if ($row['type'] == "Standard"){
include 'userareastandard.htm';
}elseif ($row['type'] == "Supplier"){
include 'userareasupplier.htm';
}elseif ($row['type'] == "Customer"){
include 'userareacustomer.htm';
}
}
} else {
include 'userlogin.htm';
}
?>
Please can someone advise?
Kindest regards,
Dee
Here is my validation code...
<?
/* Check User Script */
include 'db.php';
// Convert to simple variables
$serialnumber = $_POST['serialnumber'];
$password = $_POST['password'];
if((!$serialnumber) || (!$password)){
//if either or both fields are null then go back to userlogin.htm
include 'userlogin.htm';
exit();
}
// check if the user info validates the db
$sql = mysql_query("select * from users where serialnumber='$serialnumber' and password='$password'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach( $row AS $key => $val ){
$$key = stripslashes( $val );
}
//if the login is correct then set the cookie
$cookie_val=crypt($serialnumber);
//set the cookie so it dies when the browser is closed
setcookie ("this_cookie", $cookie_val, 0);
print($cookie_val);
//goto relevent page
if ($row['type'] == "Standard"){
include 'userareastandard.htm';
}elseif ($row['type'] == "Supplier"){
include 'userareasupplier.htm';
}elseif ($row['type'] == "Customer"){
include 'userareacustomer.htm';
}
}
} else {
include 'userlogin.htm';
}
?>
Please can someone advise?
Kindest regards,
Dee