Mercurial > owls
view Includes/Loginsys.class.php @ 9:eb5bff360deb
TIME_SESSION_EXPIRES: now class const
author | Meillo r e t u r n s <meillo@marmaro.de> |
---|---|
date | Thu, 14 Dec 2006 21:51:44 +0100 |
parents | a3a651f0cac6 |
children | 144bc36a6c27 |
line wrap: on
line source
<?php /** * simple loginsystem for owls * * @brief simple loginsystem for owls * @author Meillo r e t u r n s <meillo@marmaro.de> */ class Loginsys { /// Consts /** * time in seconds till the session expires */ const TIME_SESSION_EXPIRES = 1800; /// Constructors /** * starts the session * and puts an activity timestamp in it */ public function __construct() { session_start(); $this->heartbeat(); } /// Methods /** * trys to log in with the given login data * * @param $loginname username * @param $password_md5 md5 password hash */ public function login($loginname, $password_md5) { // login ------------------------------------ $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' ")); if (mysql_affected_rows() == 1) { // valid login $_SESSION[login][id] = $rowuser[id]; $_SESSION[login][loginname] = $loginname; $_SESSION[login][logintime] = time(); } } /** * logs the user out */ public function logout() { // logout ------------------------------------------------------------ unset($_SESSION[login]); } /** * proves if the user is logged in and if he wan't to long inactive * * @return bool 'true' if user is logged in, else 'false' */ public function loggedIn() { // return login-status --------------------------------------------- return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-self::TIME_SESSION_EXPIRES); } /** * writes the current timestamp into the session * this is relevant for the time of inactivity */ public function heartbeat() { if ($this->loggedIn()) { $_SESSION[login][logintime] = time(); } } /// Getter and Setter /** * @return user id */ public function getUserId() { return $_SESSION[login][id]; } /** * @return user name */ public function getLoginname() { return $_SESSION[login][loginname]; } } ?>