owls

diff Includes/Loginsys.class.php @ 0:3021ce32ee14

begin of using hg for owls
author "Meillo r e t u r n s <meillo@marmaro.de>"
date Sun, 03 Dec 2006 22:32:13 +0100
parents
children a3a651f0cac6
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Includes/Loginsys.class.php	Sun Dec 03 22:32:13 2006 +0100
     1.3 @@ -0,0 +1,65 @@
     1.4 +<?php
     1.5 +
     1.6 +define('TIME_SESSION_EXPIRES', 1800);
     1.7 +
     1.8 +
     1.9 +class Loginsys {
    1.10 +
    1.11 +  // Constructors
    1.12 +
    1.13 +  public function __construct() {
    1.14 +    session_start();
    1.15 +    $this->heartbeat();
    1.16 +  }
    1.17 +
    1.18 +
    1.19 +
    1.20 +
    1.21 +  // Methods
    1.22 +
    1.23 +  public function login($loginname, $password_md5) {    // login ------------------------------------
    1.24 +    $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' "));
    1.25 +    if (mysql_affected_rows() == 1) {  // valid login
    1.26 +      $_SESSION[login][id] = $rowuser[id];
    1.27 +      $_SESSION[login][loginname] = $loginname;
    1.28 +      $_SESSION[login][logintime] = time();
    1.29 +    }
    1.30 +  }
    1.31 +
    1.32 +
    1.33 +
    1.34 +  public function logout() {    // logout ------------------------------------------------------------
    1.35 +    unset($_SESSION[login]);
    1.36 +  }
    1.37 +
    1.38 +
    1.39 +
    1.40 +  public function loggedIn() {    // return login-status ---------------------------------------------
    1.41 +    return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-TIME_SESSION_EXPIRES);
    1.42 +  }
    1.43 +
    1.44 +
    1.45 +
    1.46 +  public function heartbeat() {
    1.47 +    if ($this->loggedIn()) {
    1.48 +      $_SESSION[login][logintime] = time();
    1.49 +    }
    1.50 +  }
    1.51 +
    1.52 +
    1.53 +
    1.54 +  // Getter and Setter
    1.55 +
    1.56 +  public function getUserId() {
    1.57 +    return $_SESSION[login][id];
    1.58 +  }
    1.59 +
    1.60 +
    1.61 +  public function getLoginname() {
    1.62 +    return $_SESSION[login][loginname];
    1.63 +  }
    1.64 +
    1.65 +}
    1.66 +
    1.67 +
    1.68 +?>