Sorry i didnt realise what lasorlight meant. I have put the tags around the php areas. (it also includes html).
This is the userlogin.php:
<?php
if ((!isset($_POST["username"])) ||(!isset($_POST["password"]))) {
header("Location:loginform.html");
exit;
}
$mysqli= new mysqli ("localhost", "localData", "localData", "localData");
//create and issue the query
$sql = "SELECT f_name, l_name FROM auth_users WHERE
username = '".$_POST["username"]."' AND
password = PASSWORD('".$_POST["password"]."')";
$res = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));
//get the number of rows in the result set; should be 1 if a match
if(mysqli_num_rows($res) == 1) {
//if authorized, get the values of f_name and l_name
while($info = mysqli_fetch_array($res)){
$f_name = stripslashes($info['f_name']);
$l_name = stripslashes($info['l_name']);
}
//set authorization cookie
setcookie("auth", "1", 0, "/", "yourdomain.com", 0);
//create display string
$display_block = "
<p> ".$f_name." ".$l_name." is authorized! </p>
<p>Authorized users' Menu:</p>
<ul>
<li><a href=\"secretpage.php\">Secret Page</a></li>
</ul>";
} else{
//redirect back to login form if not authorized
header ("Location: loginform.html");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Login</title>
</head>
<body>
<?php echo "$display_block"; ?>
</body>
</html>
This is the loginform.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Log in</title>
</head>
<body>
<h1>Log in form</h1>
<form method="post" action="userlogin.php">
<p><strong>username</strong>
<input type="text" name="username"/></p>
<p><strong>Password</strong>
<input type="password" name="password"/></p>
<p><input type="submit" name="submit" value="login" /></p>
</form>
</body>
</html>
And this is the secretpage.php:
<?php
if($_COOKIE["auth"] == "1" ){
$display_block = "
<p>You are an authorized user</p>";
} else {
//redirect to log in page
header("Location: loginform.html");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Secret Page</title>
</head>
<body>
<?php
echo "$display_block";
?>
</body>
</html>
As i say It recognizes the member can be authorized. But when I click "secretpage" in the browser it takes me back to the log in page instead of the secret page.
thanks for your time
cass27