Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', array(substr($_COOKIE['login'], 32), substr($_COOKIE['login'], 0, 32))); if($res->RecordCount() && $res->fields[2]) { $this->uid = $res->fields[0]; $this->gid = $res->fields[1]; $this->type = 'cookie'; $this->key = $_COOKIE['login']; } } if($this->uid == 0 && $_GET['login']) { $res = $GLOBALS['db']->Execute('SELECT id, gid, sid FROM users WHERE id = ? AND sid = ?', array(substr($_GET['login'], 32), substr($_GET['login'], 0, 32))); if($res->RecordCount() && $res->fields[2]) { $this->uid = $res->fields[0]; $this->gid = $res->fields[1]; $this->login_type = 'url'; $this->key = $_GET['login']; } } } function Login($name, $pass) { $res = $GLOBALS['db']->Execute('SELECT id, gid FROM users WHERE user = ? AND password = ?', array($name, $pass)); if($res->RecordCount()) { $id = $res->fields[0]; $sid = md5(uniqid($name . " * " . $pass . " * " . rand())); $GLOBALS['db']->Execute('UPDATE users SET sid = ? WHERE id = ?', array($sid, $id)); $this->uid = $id; $this->gid = $res->fields[1]; $this->login_type = 'url'; $this->key = $sid . $id; setcookie('login', $this->key); return $id; } return 0; } function Logout() { $GLOBALS['db']->Execute('UPDATE users SET sid = \'\' WHERE id = ?', $this->uid); $this->uid = 0; $this->gid = 0; $this->login_type = ''; $this->key = ''; setcookie('login'); } function IsAdmin() { return ($this->uid != 0 && $this->gid == 0); } } $GLOBALS['user'] = new User; ?>