testsessions.php 2.5 KB

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