我想知道是否还有其他方法可以让用户在重新访问我的网站时登录,即使会话已过期。
我目前使用的是基于cookie的方法,但我想知道是否还有人在使用其他方法。
答案 0 :(得分:4)
不,cookie旁边没有[可靠]方法。
答案 1 :(得分:2)
还有其他方法,但你应该避免使用它们,因为它们不像cookie一样可靠。
您应该努力使您的cookie使用系统更安全,而不是担心以另一种方式进行操作。
答案 2 :(得分:1)
这是一个非常古老的问题,但为了未来的访问者,我想提供一个答案。
您应该使用Cookie。像其他答案所指出的那样,它们是最可靠的方法。如果您想确保用户没有使用过期的cookie访问,请将其过期的时间写为带有校验和的cookie。
以下是使用PHP的示例:
$expireTime = time() + (60*60*24*3); // 3 days ( 60 seconds * 60 minutes * 24 hours * 3 days )
$rawPepper = openssl_random_pseudo_bytes(16);
$hexPepper = bin2hex($rawPepper);
setCookie($cookieKey, $cookieValue, $expireTime);
setCookie("expiresWhen", $expireTime, $expireTime);
setCookie("rand", $hexPepper, $expireTime);
$hash_1 = hash('sha512', "Your_Super_Secret_Salt" . $cookieValue . "Another_Super_Secret_Salt!" . $expireTime);
$hash_2 = hash('sha512', "Yet_Another_Salt!" . $hash_1. $hexPepper);
setCookie("checksum", $hash_2, $expireTime);
然后在您的其他PHP表单中进行验证,您说:
$expires = $_COOKIE['expiresWhen'];
$pepper = $_COOKIE['rand'];
$cookieVal = $_COOKIE[$cookieKey];
$givenCheckSum = $_COOKIE['checksum'];
$hash_1 = hash('sha512', "Your_Super_Secret_Salt" . $cookieVal . "Another_Super_Secret_Salt!" . $expires);
$correctCheckSum = hash('sha512', "Yet_Another_Salt!" . $hash_1. $pepper)
if($givenCheckSum != $correctCheckSum){
/* user's cookie has expired. Handle as you please */
}else{
/* Cookie is still valid */
}
是否有人愿意对此进行更正或提供建议?