Revision 1, 1.6 KB
(checked in by andrewgunn, 14 years ago)
|
Added original EVE-Killboard.net source code.
|
Line | |
---|
1 | <? |
---|
2 | require_once( "db.php" ); |
---|
3 | |
---|
4 | class Session { |
---|
5 | |
---|
6 | function Session( $cookie, $ip ) |
---|
7 | { |
---|
8 | $this->qry_ = new DBQuery(); |
---|
9 | $this->sql_ = "select * |
---|
10 | from kb3_sessions ses |
---|
11 | where ses.ses_id = '".$cookie."' |
---|
12 | and ses.ses_ip = '".$ip."'"; |
---|
13 | } |
---|
14 | |
---|
15 | function isAdmin() |
---|
16 | { |
---|
17 | $this->execQuery(); |
---|
18 | return $this->qry_->recordCount() == 1; |
---|
19 | } |
---|
20 | |
---|
21 | function isSuperAdmin() |
---|
22 | { |
---|
23 | $this->execQuery(); |
---|
24 | return $this->qry_->recordCount() == 1 && $this->row_['ses_super'] = 1; |
---|
25 | } |
---|
26 | |
---|
27 | function execQuery() |
---|
28 | { |
---|
29 | if ( !$this->qry_->executed_ ) |
---|
30 | $this->qry_->execute( $this->sql_ ); |
---|
31 | |
---|
32 | $this->row_ = $this->qry_->getRow(); |
---|
33 | } |
---|
34 | |
---|
35 | function cleanup() |
---|
36 | { |
---|
37 | $qry = new DBQuery(); |
---|
38 | $qry->execute( "delete from kb3_sessions |
---|
39 | where ses_logon < date_sub( now(), |
---|
40 | INTERVAL '120:0' |
---|
41 | MINUTE_SECOND )" ); |
---|
42 | } |
---|
43 | |
---|
44 | function create( $super ) |
---|
45 | { |
---|
46 | $current = time(); |
---|
47 | $random = $_SERVER['REMOTE_ADDR'].$current.KB_SITE; |
---|
48 | $ses_id = md5( $random ); |
---|
49 | |
---|
50 | if ( !setcookie( "EVK_COOKIE", $ses_id, 0 ) ) |
---|
51 | die( "Unable to set cookie" ); |
---|
52 | |
---|
53 | $qry = new DBQuery(); |
---|
54 | $qry->execute( "insert into kb3_sessions values ( '".$ses_id."', |
---|
55 | '".$_SERVER['REMOTE_ADDR']."', |
---|
56 | now(), |
---|
57 | ".$super." )" ); |
---|
58 | |
---|
59 | } |
---|
60 | } |
---|
61 | ?> |
---|