Mercurial > owls
comparison Includes/Loginsys.class.php @ 0:3021ce32ee14 owls-0.5
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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3021ce32ee14 |
---|---|
1 <?php | |
2 | |
3 define('TIME_SESSION_EXPIRES', 1800); | |
4 | |
5 | |
6 class Loginsys { | |
7 | |
8 // Constructors | |
9 | |
10 public function __construct() { | |
11 session_start(); | |
12 $this->heartbeat(); | |
13 } | |
14 | |
15 | |
16 | |
17 | |
18 // Methods | |
19 | |
20 public function login($loginname, $password_md5) { // login ------------------------------------ | |
21 $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' ")); | |
22 if (mysql_affected_rows() == 1) { // valid login | |
23 $_SESSION[login][id] = $rowuser[id]; | |
24 $_SESSION[login][loginname] = $loginname; | |
25 $_SESSION[login][logintime] = time(); | |
26 } | |
27 } | |
28 | |
29 | |
30 | |
31 public function logout() { // logout ------------------------------------------------------------ | |
32 unset($_SESSION[login]); | |
33 } | |
34 | |
35 | |
36 | |
37 public function loggedIn() { // return login-status --------------------------------------------- | |
38 return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-TIME_SESSION_EXPIRES); | |
39 } | |
40 | |
41 | |
42 | |
43 public function heartbeat() { | |
44 if ($this->loggedIn()) { | |
45 $_SESSION[login][logintime] = time(); | |
46 } | |
47 } | |
48 | |
49 | |
50 | |
51 // Getter and Setter | |
52 | |
53 public function getUserId() { | |
54 return $_SESSION[login][id]; | |
55 } | |
56 | |
57 | |
58 public function getLoginname() { | |
59 return $_SESSION[login][loginname]; | |
60 } | |
61 | |
62 } | |
63 | |
64 | |
65 ?> |