我正在为网站构建一个管理面板,我已经编写了身份验证代码,但我不确定它有多安全。
这不是登录脚本,但它会利用登录脚本设置的一些会话变量。
无论如何,就在这里,希望你能帮我检查一下(:
if (isset($_SESSION['logged_in'])) {
//Prevent hijacking of the session
$recreatesignature = $_SESSION['signature']; //signature (old)
$recreatessalt = $_SESSION['salt']; //session salt (old)
$useragent = $_SERVER['HTTP_USER_AGENT']; //useragent (new)
$ip = $_SERVER['REMOTE_ADDR']; //ip (new)
$signature = $salt.sha1($ip.$recreatessalt.$useragent); //signature (hash)
//Compare signatures
if (!($recreatesignature==$signature)) {
header(sprintf("Location: %s", $domain));
exit();
}
//Session timeout
if ((isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > $sessiontimeout))) {
//destroy session
session_destroy();
session_unset();
//redirect to home page
header(sprintf("Location: %s", $domain));
}
$_SESSION['LAST_ACTIVITY'] = time();
//Generate new session id to make hijacking harder
session_regenerate_id(TRUE);
}