PageRenderTime 44ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/include/adodb/tests/testsessions.php

https://github.com/radicaldesigns/amp
PHP | 90 lines | 45 code | 26 blank | 19 comment | 7 complexity | 439cfa48542dcf29b0636c6768dccf8e MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause, LGPL-2.0, CC-BY-SA-3.0, AGPL-1.0
  1. <?php
  2. /*
  3. V4.80 8 Mar 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
  4. Released under both BSD license and Lesser GPL library license.
  5. Whenever there is any discrepancy between the two licenses,
  6. the BSD license will take precedence.
  7. Set tabs to 4 for best viewing.
  8. Latest version is available at http://adodb.sourceforge.net
  9. */
  10. function NotifyExpire($ref,$key)
  11. {
  12. print "<p><b>Notify Expiring=$ref, sessionkey=$key</b></p>";
  13. }
  14. //-------------------------------------------------------------------
  15. error_reporting(E_ALL);
  16. ob_start();
  17. include('../session/adodb-cryptsession2.php');
  18. $options['debug'] = 99;
  19. $db = 'postgres';
  20. #### CONNECTION
  21. switch($db) {
  22. case 'oci8':
  23. $options['table'] = 'adodb_sessions2';
  24. ADOdb_Session::config('oci8', '', 'jcollect', 'natsoft', '',$options);
  25. break;
  26. case 'postgres':
  27. ADOdb_Session::config('postgres', 'localhost', 'tester', 'test', 'test',$options);
  28. break;
  29. case 'mysql':
  30. default:
  31. ADOdb_Session::config('mysql', 'localhost', 'root', '', 'xphplens_2',$options);
  32. break;
  33. }
  34. #### SETUP NOTIFICATION
  35. $USER = 'JLIM'.rand();
  36. $ADODB_SESSION_EXPIRE_NOTIFY = array('USER','NotifyExpire');
  37. adodb_session_create_table();
  38. session_start();
  39. adodb_session_regenerate_id();
  40. ### SETUP SESSION VARIABLES
  41. if (empty($_SESSION['MONKEY'])) $_SESSION['MONKEY'] = array(1,'abc',44.41);
  42. else $_SESSION['MONKEY'][0] += 1;
  43. if (!isset($_GET['nochange'])) @$_SESSION['AVAR'] += 1;
  44. ### START DISPLAY
  45. print "<h3>PHP ".PHP_VERSION."</h3>";
  46. print "<p><b>\$_SESSION['AVAR']={$_SESSION['AVAR']}</b></p>";
  47. print "<hr /> <b>Cookies</b>: ";
  48. print_r($_COOKIE);
  49. var_dump($_SESSION['MONKEY']);
  50. ### RANDOMLY PERFORM Garbage Collection
  51. ### In real-production environment, this is done for you
  52. ### by php's session extension, which calls adodb_sess_gc()
  53. ### automatically for you. See php.ini's
  54. ### session.cookie_lifetime and session.gc_probability
  55. if (rand() % 5 == 0) {
  56. print "<hr /><p><b>Garbage Collection</b></p>";
  57. adodb_sess_gc(10);
  58. if (rand() % 2 == 0) {
  59. print "<p>Random session destroy</p>";
  60. session_destroy();
  61. }
  62. }
  63. ?>