form submit { email|password }
php filter/check { mysql_real_escape_string etc... }
php set/login.php {
$hash_logged = sha1(rand(100000,999999).$_SERVER["REMOTE_ADDR"].time());
$_SESSION["hl"] = $hash_logged;
mysql_query("UPDATE `users` SET `hash_logged`='".$hash_logged."' WHERE
`email`='".$emailLogin."'")or die(mysql_error());
setcookie("hlc", sha1($emailLogin."longstringtoguess"), time() + 600);
}
所有 files.php 顶部的 php 脚本以验证用户是否已登录:
if(isset($_SESSION["hl"], $_COOKIE["hlc"]))
{
$ext_hl =$_SESSION["hl"];
$ext_cookie = $_COOKIE["hlc"];
if(empty($ext_hl)) { header("location: logout.php"); exit(); }
if(empty($ext_cookie)) { header("location: logout.php"); exit(); }
$mysqlQ = mysql_query("SELECT `id`, `username`, `email`, `password` FROM `users`
WHERE `hash_logged`='".$ext_hl."'")or die(mysql_error());
if(mysql_num_rows($mysqlQ) == 1)
{
$row = mysql_fetch_array($mysqlQ);
if(sha1($row["email"]."longstringtoguess") == $ext_cookie)
{
$logged = "yes";
}
else {
header("location: logout.php");
exit();
}
}
else { header("location: logout.php"); exit(); }
}
注销.php
会话销毁/取消设置标头位置:index.php
这种方法足够安全吗?你有什么办法做到这一点?
谢谢