請看一下這段代碼。是否可以使用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(); }
1 回答

翻翻過去那場雪
TA貢獻2065條經驗 獲得超14個贊
這是可能的,但我不建議你這樣做。特別是在 cookie 中存儲可能未加密的密碼。
您可以在 cookie 中存儲會話 ID,并將該代碼存儲在數據庫中。這樣您就可以“記住”誰通過該特定瀏覽器使用了您的網站,以及用戶是否已注銷。現在,您無需將未加密的敏感信息存儲在易于訪問的 cookie 中。
if(isset($_COOKIE['sessionid']) {
//looking for that session id in the database here... your object is $session filled data from the database.
if($session->stillLogged()) {
//Authenticate the user..
}
}
- 1 回答
- 0 關注
- 132 瀏覽
添加回答
舉報
0/150
提交
取消