setcookie html php,html - PHP setcookie() Issues - Stack Overflow

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 Menu

Which 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?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值