gpt4 book ai didi

PHP 记住我,COOKIE

转载 作者:可可西里 更新时间:2023-11-01 01:04:48 25 4
gpt4 key购买 nike

我不知道哪里出了问题。当我勾选记住我复选框时该页面没有转到用户区域页面,并且 cookie 似乎也没有工作当我只是登录而不勾选记住我复选框时它会起作用

<?PHP
session_start();

$connect=mysql_connect("localhost", "root", "");
mysql_select_db("phplogin", $connect);


function loggedin(){
if(isset($_SESSION['email']) || isset($_COOKIE['username'])){
$loggedin=TRUE;
return $loggedin;
}
}

if(loggedin()){
header("Location:userarea.php");}

if(isset($_POST['login'])){

$email=$_POST['email'];
$password=$_POST['password'];
$rememberme=$_POST['rememberme'];

if($email && $password){
$login=mysql_query("SELECT * FROM users WHERE email='$email'");
while($row=mysql_fetch_assoc($login)){
$db_email=$row['email'];
$db_password=$row['password'];
$db_firstname=$row['firstname'];
$db_lastname=$row['lastname'];

if($password==$db_password){$log=TRUE;}
else{$log=FALSE;}
}

if($log==TRUE){
if($rememberme=="on"){
setcookie("email", $email, time()+7200);
}
else if($rememberme==""){
$_SESSION['email']=$email;
header("Location:userarea.php");
}
}
else{die("Wrong email or password");}
}
}
?>

<html>
<form action="index.php" method="POST">
<input type="text" name="email" value="" placeholder="email" /><br/>
<input type="password" name="password" value="" placeholder="password"/><br/>

<input type="checkbox" name="rememberme"> Remember me | <a href="register.php">Register?</a><br/>
<input type="submit" name="login" value="Login" />
</form>
</html>

最佳答案

函数 loggedin() 中的 cookie 变量名称错误。它应该是 isset($_COOKIE['email'])

function loggedin(){
if(isset($_SESSION['email']) || isset($_COOKIE['email'])){
$loggedin=TRUE;
return $loggedin;
}
}

关于PHP 记住我,COOKIE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13740273/

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