[2] | 1 | <?php |
---|
| 2 | |
---|
| 3 | /* |
---|
[8222] | 4 | V4.80 8 Mar 2006 (c) 2000-2012 John Lim (jlim#natsoft.com). All rights reserved. |
---|
[2] | 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 | |
---|
[34] | 20 | error_reporting(E_ALL); |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | ob_start(); |
---|
| 24 | include('../session/adodb-cryptsession2.php'); |
---|
| 25 | |
---|
[8222] | 26 | |
---|
| 27 | $options['debug'] = 1; |
---|
[34] | 28 | $db = 'postgres'; |
---|
| 29 | |
---|
| 30 | #### CONNECTION |
---|
| 31 | switch($db) { |
---|
| 32 | case 'oci8': |
---|
| 33 | $options['table'] = 'adodb_sessions2'; |
---|
[8222] | 34 | ADOdb_Session::config('oci8', 'mobydick', 'jdev', 'natsoft', 'mobydick',$options); |
---|
[34] | 35 | break; |
---|
| 36 | |
---|
| 37 | case 'postgres': |
---|
[8222] | 38 | $options['table'] = 'sessions2'; |
---|
| 39 | ADOdb_Session::config('postgres', 'localhost', 'postgres', 'natsoft', 'northwind',$options); |
---|
[34] | 40 | break; |
---|
[2] | 41 | |
---|
[34] | 42 | case 'mysql': |
---|
| 43 | default: |
---|
[8222] | 44 | $options['table'] = 'sessions2'; |
---|
[34] | 45 | ADOdb_Session::config('mysql', 'localhost', 'root', '', 'xphplens_2',$options); |
---|
| 46 | break; |
---|
| 47 | |
---|
| 48 | |
---|
[2] | 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | #### SETUP NOTIFICATION |
---|
| 54 | $USER = 'JLIM'.rand(); |
---|
| 55 | $ADODB_SESSION_EXPIRE_NOTIFY = array('USER','NotifyExpire'); |
---|
| 56 | |
---|
[34] | 57 | adodb_session_create_table(); |
---|
[2] | 58 | session_start(); |
---|
| 59 | |
---|
[34] | 60 | adodb_session_regenerate_id(); |
---|
| 61 | |
---|
[2] | 62 | ### SETUP SESSION VARIABLES |
---|
[34] | 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; |
---|
[2] | 66 | |
---|
| 67 | |
---|
| 68 | ### START DISPLAY |
---|
| 69 | print "<h3>PHP ".PHP_VERSION."</h3>"; |
---|
[34] | 70 | print "<p><b>\$_SESSION['AVAR']={$_SESSION['AVAR']}</b></p>"; |
---|
[2] | 71 | |
---|
[34] | 72 | print "<hr /> <b>Cookies</b>: "; |
---|
| 73 | print_r($_COOKIE); |
---|
[2] | 74 | |
---|
[34] | 75 | var_dump($_SESSION['MONKEY']); |
---|
| 76 | |
---|
[2] | 77 | ### RANDOMLY PERFORM Garbage Collection |
---|
[34] | 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) { |
---|
[2] | 84 | |
---|
[34] | 85 | print "<hr /><p><b>Garbage Collection</b></p>"; |
---|
[2] | 86 | adodb_sess_gc(10); |
---|
| 87 | |
---|
[34] | 88 | if (rand() % 2 == 0) { |
---|
[8222] | 89 | print "<p>Random own session destroy</p>"; |
---|
[34] | 90 | session_destroy(); |
---|
| 91 | } |
---|
[8222] | 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)"); |
---|
[2] | 98 | } |
---|
| 99 | ?> |
---|