本文整理汇总了PHP中Authenticate::superuser方法的典型用法代码示例。如果您正苦于以下问题:PHP Authenticate::superuser方法的具体用法?PHP Authenticate::superuser怎么用?PHP Authenticate::superuser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Authenticate
的用法示例。
在下文中一共展示了Authenticate::superuser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Login
public static function Login()
{
$DB = GetDB();
self::$authenticated = false;
self::$superuser = false;
self::$username = null;
$cookie_settings = self::GetCookieSettings();
if (isset($_REQUEST[self::FIELD_USERNAME])) {
if (String::IsEmpty($_REQUEST[self::FIELD_USERNAME])) {
self::$error = 'The username field was left blank';
return;
}
if (String::IsEmpty($_REQUEST[self::FIELD_PASSWORD])) {
self::$error = 'The password field was left blank';
return;
}
$account = $DB->Row('SELECT * FROM `tbx_administrator` WHERE `username`=? AND `password`=?', array($_REQUEST[self::FIELD_USERNAME], sha1($_REQUEST[self::FIELD_PASSWORD])));
if (!$account) {
self::$error = 'The supplied username/password combination is not valid';
return;
} else {
$session = sha1(uniqid(rand(), true));
$DB->Update('INSERT INTO `tbx_administrator_session` VALUES (?,?,?,?,?)', array($account['username'], $session, sha1($_SERVER['HTTP_USER_AGENT']), $_SERVER['REMOTE_ADDR'], time()));
$DB->Update('INSERT INTO `tbx_administrator_login_history` VALUES (?,?,?)', array($account['username'], Database_MySQL::Now(), $_SERVER['REMOTE_ADDR']));
setcookie(self::COOKIE_NAME, self::FIELD_USERNAME . '=' . urlencode($account['username']) . '&' . self::FIELD_SESSION . '=' . urlencode($session), $_REQUEST[self::FIELD_REMEMBER] ? time() + self::SESSION_LENGTH : null, $cookie_settings['path'], $cookie_settings['domain']);
self::$username = $account['username'];
self::$superuser = $account['type'] == self::TYPE_SUPERUSER;
self::$privileges = $account['privileges'];
self::$authenticated = true;
}
} else {
if (isset($_COOKIE[self::COOKIE_NAME])) {
$cookie = array();
parse_str($_COOKIE[self::COOKIE_NAME], $cookie);
$DB->Update('DELETE FROM `tbx_administrator_session` WHERE `timestamp` < ?', array(time() - self::SESSION_LENGTH));
$session = $DB->Row('SELECT * FROM `tbx_administrator_session` WHERE `username`=? AND `session`=? AND `browser`=? AND `ip_address`=?', array($cookie[self::FIELD_USERNAME], $cookie[self::FIELD_SESSION], sha1($_SERVER['HTTP_USER_AGENT']), $_SERVER['REMOTE_ADDR']));
if (!$session) {
setcookie(self::COOKIE_NAME, false, time() - self::SESSION_LENGTH, $cookie_settings['path'], $cookie_settings['domain']);
self::$error = 'Your control panel session has expired';
return;
} else {
$account = $DB->Row('SELECT * FROM `tbx_administrator` WHERE `username`=?', array($session['username']));
if (!$account) {
setcookie(self::COOKIE_NAME, false, time() - self::SESSION_LENGTH, $cookie_settings['path'], $cookie_settings['domain']);
self::$error = 'Invalid control panel account';
return;
} else {
self::$username = $account['username'];
self::$superuser = $account['type'] == self::TYPE_SUPERUSER;
self::$privileges = $account['privileges'];
self::$authenticated = true;
}
}
}
}
return self::$authenticated;
}