1 | <?php |
---|
2 | |
---|
3 | /* |
---|
4 | V4.80 8 Mar 2006 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. |
---|
5 | Released under both BSD license and Lesser GPL library license. |
---|
6 | Whenever there is any discrepancy between the two licenses, |
---|
7 | the BSD license will take precedence. |
---|
8 | Set tabs to 4 for best viewing. |
---|
9 | |
---|
10 | Latest version is available at http://adodb.sourceforge.net |
---|
11 | */ |
---|
12 | |
---|
13 | function NotifyExpire($ref,$key) |
---|
14 | { |
---|
15 | print "<p><b>Notify Expiring=$ref, sessionkey=$key</b></p>"; |
---|
16 | } |
---|
17 | |
---|
18 | //------------------------------------------------------------------- |
---|
19 | |
---|
20 | error_reporting(E_ALL); |
---|
21 | |
---|
22 | |
---|
23 | ob_start(); |
---|
24 | include('../session/adodb-cryptsession2.php'); |
---|
25 | |
---|
26 | |
---|
27 | $options['debug'] = 1; |
---|
28 | $db = 'postgres'; |
---|
29 | |
---|
30 | #### CONNECTION |
---|
31 | switch($db) { |
---|
32 | case 'oci8': |
---|
33 | $options['table'] = 'adodb_sessions2'; |
---|
34 | ADOdb_Session::config('oci8', 'mobydick', 'jdev', 'natsoft', 'mobydick',$options); |
---|
35 | break; |
---|
36 | |
---|
37 | case 'postgres': |
---|
38 | $options['table'] = 'sessions2'; |
---|
39 | ADOdb_Session::config('postgres', 'localhost', 'postgres', 'natsoft', 'northwind',$options); |
---|
40 | break; |
---|
41 | |
---|
42 | case 'mysql': |
---|
43 | default: |
---|
44 | $options['table'] = 'sessions2'; |
---|
45 | ADOdb_Session::config('mysql', 'localhost', 'root', '', 'xphplens_2',$options); |
---|
46 | break; |
---|
47 | |
---|
48 | |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | #### SETUP NOTIFICATION |
---|
54 | $USER = 'JLIM'.rand(); |
---|
55 | $ADODB_SESSION_EXPIRE_NOTIFY = array('USER','NotifyExpire'); |
---|
56 | |
---|
57 | adodb_session_create_table(); |
---|
58 | session_start(); |
---|
59 | |
---|
60 | adodb_session_regenerate_id(); |
---|
61 | |
---|
62 | ### SETUP SESSION VARIABLES |
---|
63 | if (empty($_SESSION['MONKEY'])) $_SESSION['MONKEY'] = array(1,'abc',44.41); |
---|
64 | else $_SESSION['MONKEY'][0] += 1; |
---|
65 | if (!isset($_GET['nochange'])) @$_SESSION['AVAR'] += 1; |
---|
66 | |
---|
67 | |
---|
68 | ### START DISPLAY |
---|
69 | print "<h3>PHP ".PHP_VERSION."</h3>"; |
---|
70 | print "<p><b>\$_SESSION['AVAR']={$_SESSION['AVAR']}</b></p>"; |
---|
71 | |
---|
72 | print "<hr /> <b>Cookies</b>: "; |
---|
73 | print_r($_COOKIE); |
---|
74 | |
---|
75 | var_dump($_SESSION['MONKEY']); |
---|
76 | |
---|
77 | ### RANDOMLY PERFORM Garbage Collection |
---|
78 | ### In real-production environment, this is done for you |
---|
79 | ### by php's session extension, which calls adodb_sess_gc() |
---|
80 | ### automatically for you. See php.ini's |
---|
81 | ### session.cookie_lifetime and session.gc_probability |
---|
82 | |
---|
83 | if (rand() % 5 == 0) { |
---|
84 | |
---|
85 | print "<hr /><p><b>Garbage Collection</b></p>"; |
---|
86 | adodb_sess_gc(10); |
---|
87 | |
---|
88 | if (rand() % 2 == 0) { |
---|
89 | print "<p>Random own session destroy</p>"; |
---|
90 | session_destroy(); |
---|
91 | } |
---|
92 | } else { |
---|
93 | $DB = ADODB_Session::_conn(); |
---|
94 | $sessk = $DB->qstr('%AZ'.rand().time()); |
---|
95 | $olddate = $DB->DBTimeStamp(time()-30*24*3600); |
---|
96 | $rr = $DB->qstr(rand()); |
---|
97 | $DB->Execute("insert into {$options['table']} (sesskey,expiry,expireref,sessdata,created,modified) values ($sessk,$olddate, $rr,'',$olddate,$olddate)"); |
---|
98 | } |
---|
99 | ?> |
---|