请看一下这段代码。是否可以使用cookies来注册用户
if (isset($_COOKIE['rand_nm']) && isset($_COOKIE['token'])) {
$start_date = date("Y-m-d h:i:sa");
$stmt = $con->prepare("SELECT * From tbl_token Where username = ? AND selector_hash = ?");
$stmt->execute(array($_COOKIE['rand_nm'], $_COOKIE['token']));
$row = $stmt->fetch();
$count = $stmt->rowCount();
if($row["expiry_date"] >= $start_date) {
$isExpiryDareVerified = true;
}
if ($_COOKIE['rand_nm'] == $row['username'] && $_COOKIE['token'] == $row['selector_hash'] && $isExpiryDareVerified) {
if ($count > 0) {
$_SESSION['userName'] = $row['username'];
$_SESSION['id'] = $row['id'];
}
}
}
提交表单时处理表单数据并更新数据库表
,然后存储cookies信息。数据库中的令牌[随机数]和用户名。登录后...
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['login'])) {
$user = $_POST['username'];
$pass = $_POST['password'];
$hashPass = sha1($pass);
if (empty($_POST['username']) || empty($_POST['password'])) {
header('Location: signup.php?error=fieldsempty');
exit();
}
翻翻过去那场雪