|
Adodb Dokumentation
V5.14 8 Sept 2011
|
00001 <?php 00002 00003 /* 00004 V4.80 8 Mar 2006 (c) 2000-2011 John Lim (jlim#natsoft.com). All rights reserved. 00005 Released under both BSD license and Lesser GPL library license. 00006 Whenever there is any discrepancy between the two licenses, 00007 the BSD license will take precedence. 00008 Set tabs to 4 for best viewing. 00009 00010 Latest version is available at http://adodb.sourceforge.net 00011 */ 00012 00013 function NotifyExpire($ref,$key) 00014 { 00015 print "<p><b>Notify Expiring=$ref, sessionkey=$key</b></p>"; 00016 } 00017 00018 //------------------------------------------------------------------- 00019 00020 error_reporting(E_ALL); 00021 00022 00023 ob_start(); 00024 include('../session/adodb-cryptsession2.php'); 00025 00026 00027 $options['debug'] = 1; 00028 $db = 'postgres'; 00029 00030 #### CONNECTION 00031 switch($db) { 00032 case 'oci8': 00033 $options['table'] = 'adodb_sessions2'; 00034 ADOdb_Session::config('oci8', 'mobydick', 'jdev', 'natsoft', 'mobydick',$options); 00035 break; 00036 00037 case 'postgres': 00038 $options['table'] = 'sessions2'; 00039 ADOdb_Session::config('postgres', 'localhost', 'postgres', 'natsoft', 'northwind',$options); 00040 break; 00041 00042 case 'mysql': 00043 default: 00044 $options['table'] = 'sessions2'; 00045 ADOdb_Session::config('mysql', 'localhost', 'root', '', 'xphplens_2',$options); 00046 break; 00047 00048 00049 } 00050 00051 00052 00053 #### SETUP NOTIFICATION 00054 $USER = 'JLIM'.rand(); 00055 $ADODB_SESSION_EXPIRE_NOTIFY = array('USER','NotifyExpire'); 00056 00057 adodb_session_create_table(); 00058 session_start(); 00059 00060 adodb_session_regenerate_id(); 00061 00062 ### SETUP SESSION VARIABLES 00063 if (empty($_SESSION['MONKEY'])) $_SESSION['MONKEY'] = array(1,'abc',44.41); 00064 else $_SESSION['MONKEY'][0] += 1; 00065 if (!isset($_GET['nochange'])) @$_SESSION['AVAR'] += 1; 00066 00067 00068 ### START DISPLAY 00069 print "<h3>PHP ".PHP_VERSION."</h3>"; 00070 print "<p><b>\$_SESSION['AVAR']={$_SESSION['AVAR']}</b></p>"; 00071 00072 print "<hr /> <b>Cookies</b>: "; 00073 print_r($_COOKIE); 00074 00075 var_dump($_SESSION['MONKEY']); 00076 00077 ### RANDOMLY PERFORM Garbage Collection 00078 ### In real-production environment, this is done for you 00079 ### by php's session extension, which calls adodb_sess_gc() 00080 ### automatically for you. See php.ini's 00081 ### session.cookie_lifetime and session.gc_probability 00082 00083 if (rand() % 5 == 0) { 00084 00085 print "<hr /><p><b>Garbage Collection</b></p>"; 00086 adodb_sess_gc(10); 00087 00088 if (rand() % 2 == 0) { 00089 print "<p>Random own session destroy</p>"; 00090 session_destroy(); 00091 } 00092 } else { 00093 $DB = ADODB_Session::_conn(); 00094 $sessk = $DB->qstr('%AZ'.rand().time()); 00095 $olddate = $DB->DBTimeStamp(time()-30*24*3600); 00096 $rr = $DB->qstr(rand()); 00097 $DB->Execute("insert into {$options['table']} (sesskey,expiry,expireref,sessdata,created,modified) values ($sessk,$olddate, $rr,'',$olddate,$olddate)"); 00098 } 00099 ?>