gpt4 book ai didi

php cookie 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:37:09 24 4
gpt4 key购买 nike

我正在尝试使用带有身份验证的 cookie。

这个页面一旦进入用户并通过

   <?
if ((!$_POST[username]) || (!$_POST[password])) {
header("Location: show_login.html");
exit;
}
$db_name = "testDB";
$table_name = "auth_users";
$connection = @mysql_connect("localhost", "user", "pass") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE username ='$_POST[username]' AND password = password('$_POST[password]')";
$result = @mysql_query($sql, $connection) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num != 0) {
$cookie_name = "auth";
$cookie_value = "ok";
$cookie_expire = "0";
$cookie_domain = "domain.com.au";
setcookie($cookie_name, $cookis_value, $cookie_expire, "/", $cookie_domain, 0);
$display_block = "
<p><strong>Secret Menu:</strong></p>
<ul>
<li><a href=\"secretA.php\">secret page A</a>
<li><a href=\"secretB.php\">secret page B</a>
</ul>";
} else {
header("Location: show_login.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=utf-8" />
<title>Secret Area</title>
</head>

<body>
<? echo "$display_block"; ?>


</body>
</html>

当我点击 secretA.php 或 secretB.php 时,我被重定向到再次登录,它应该可以工作。这是代码。 secret B.php

<?php

if ($_COOKIE[auth] == "ok") {
$msg = "<p>Welcome to secret page B, authorised user! </P>";
} else {
header( "Location: /show_login.html");
exit;
}
?>
<HTML>
<HEAD>
<title>Secret Page B:</title>
</HEAD>
<BODY>

<? echo "$msg"; ?>

</BODY>
</HTML>

最佳答案

这里有些东西可能把你搞砸了......

setcookie($cookie_name,$cookies_value, $cookie_expire, "/", $cookie_domain, 0);

关于php cookie 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2703545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com