我正在尝试在登录表单中记住我的选项。每次我尝试使用令牌值更新表时,此值特别不会更新,并且在更新过程后始终返回空,尽管已创建cookie和会话。这是我的PHP代码。
<?php
$dbc=mysqli_connect('localhost','root','','store') or die('Can\'t connect.');
session_start();+
{
if(isset($_POST['submit_login'])) {
$login_username=$_POST['user_name_login'];
$login_password=$_POST['password_login'];
$statement=mysqli_stmt_init($dbc);
if (mysqli_stmt_prepare($statement, "SELECT * FROM customers_info WHERE user_name=?")) {
mysqli_stmt_bind_param($statement,"s",$login_username);
mysqli_stmt_execute($statement);
$result=mysqli_stmt_get_result($statement);
$num=mysqli_num_rows($result);
}
if($num==1) {
while ($row=mysqli_fetch_assoc($result)) {
$user_name=$row['user_name'];
$enc_user_name=password_hash($user_name,PASSWORD_DEFAULT);
$user_friend=bin2hex(random_bytes(32));
$token=password_hash($user_friend);
$user_signature="$enc_user_name"."___"."$user_friend";
//=====================================================================
if(password_verify($login_password,$row['password'])) {
$_SESSION['user_name']=$user_name;
if(isset($_POST['rememberme'])) {
mysqli_query($dbc,"UPDATE customers_info
SET myenc='$token'
WHERE user_name='$user_name'");
setcookie('cats_love_balls',$user_signature,(time()-3600));
}
header('Location: myfile.php');
}
//===================================================================
}
}
} else {
echo 'not found';
}
}
?>
这是创建mytable的mysql语句:
CREATE TABLE `customers_info` (
`user_name` varchar(50) NOT NULL,
`password` varchar(255) DEFAULT NULL,
`first_name` varchar(50) DEFAULT NULL,
`last_name` varchar(50) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`myenc` varchar(300) DEFAULT NULL,
PRIMARY KEY (`user_name`)
);
我不知道这是否重要,但我使用的是Ubuntu 16.04 如果你愿意,我需要你的帮助来解决我的问题。