I have a php file:
$username = $_POST["username"];
if((!$username) || (!$_POST["password"])){
header("Location:http://localhost/login.html");
exit;
}
$db_name = "muzak";
$tblname = "auth_users";
$connection = mysqli_connect("localhost", "***username***", "***password***", $db_name) or die("Couldn't connect to database");
$sql = "SELECT * FROM $tblname WHERE username = '$username' AND password= password('$_POST[password]')";
$result = mysqli_query($connection, $sql) or die(mysqli_error($connection));
$numHits = mysqli_num_rows($result);
var_dump($numHits);//equal to one
if($numHits > 0){
$cookie_name = "auth";
$cookie_value = "ok";
$cookie_expire = "0";
$cookie_domain = "127.0.0.1";
setcookie($cookie_name, $cookie_value, $cookie_expire, "/" , $cookie_domain, 0);
$display = "
Secret Area A Secret Area B ";}else{
header("Location:http://localhost/login.html");
}
?>
Secret MenuWhich takes input from an html file and asks a database for confirmation. The HTML part works fine, but when I try to check for the presence of the cookie in the secret_areaA.php file . . .
if($_COOKIE["auth"] == "ok"){
$msg = "
";
}else{
die("Cookie wasn't valid");
}
?>
Secret Area A
I get this error: Notice: Undefined index: auth in C:\xampp\htdocs\secret_areaA.php on line 2.
What am I doing wrong?