我正在尝试设置Cookie,但不能,我的代码
if (mysqli_num_rows($data)>0) {
if (isset($_POST["loggedin"])) {
setcookie("RAUSERNAME", $USERNAME,time() + (86400 * 365 * 1000),"/");
setcookie("RAPASSWORD", $PASSWORD,time() + (86400 * 365 * 1000),"/");
}
$_SESSION["SRAUSERNAME"] = $USERNAME;
$_SESSION["SRAPASSWORD"] = $PASSWORD;
header("location: ../");
}
通过回显cookie,它不会打印任何东西或根本没有设置。
答案 0 :(得分:0)
试试这个..
<?php
if (mysqli_num_rows($data)>0) {
if (isset($_POST["loggedin"])) {
$cookie_name = $_POST["USERNAME"];
$cookie_passoword = $_POST["PASSWORD"];
setcookie($cookie_name, $cookie_passoword,time() + (86400 * 30),"/"); // 1 Day oR ( 365 * 24 * 60 * 60),"/"); // For 1 Year
}
$_SESSION[$cookie_name] = $USERNAME;
$_SESSION[$cookie_passoword] = $PASSWORD;
if(!isset($_COOKIE[$cookie_name]) && !isset($_COOKIE[$cookie_passoword]) ) {
echo "Cookie named '" . $cookie_name . "' and '".$cookie_passoword."' is not set!";
} else {
echo "Cookie Name Is '" . $_COOKIE[$cookie_name]. "' is set!<br>";
echo "Password is: " . $_COOKIE[$cookie_passoword];
}
header("location: ../");
}
?>
答案 1 :(得分:-1)
谢谢,大家提出建议。真正的问题在于我设置的cookie的时间,在减少之后,它运行良好。