HTTP_Session2
[ class tree: HTTP_Session2 ] [ index: HTTP_Session2 ] [ all elements ]

Source for file HTTP_Session2_Example.php

Documentation is available at HTTP_Session2_Example.php

  1. <?php
  2. //
  3. // +-----------------------------------------------------------------------+
  4. // | Copyright (c) 2002, Alexander Radivanovich                            |
  5. // | All rights reserved.                                                  |
  6. // |                                                                       |
  7. // | Redistribution and use in source and binary forms, with or without    |
  8. // | modification, are permitted provided that the following conditions    |
  9. // | are met:                                                              |
  10. // |                                                                       |
  11. // | o Redistributions of source code must retain the above copyright      |
  12. // |   notice, this list of conditions and the following disclaimer.       |
  13. // | o Redistributions in binary form must reproduce the above copyright   |
  14. // |   notice, this list of conditions and the following disclaimer in the |
  15. // |   documentation and/or other materials provided with the distribution.|
  16. // | o The names of the authors may not be used to endorse or promote      |
  17. // |   products derived from this software without specific prior written  |
  18. // |   permission.                                                         |
  19. // |                                                                       |
  20. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
  21. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
  22. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
  23. // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
  24. // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  25. // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
  26. // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  27. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  28. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
  29. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  30. // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
  31. // |                                                                       |
  32. // +-----------------------------------------------------------------------+
  33. // | Author: Alexander Radivanovich <info@wwwlab.net>                      |
  34. // +-----------------------------------------------------------------------+
  35. //
  36.  
  37. //ob_start(); //-- For easy debugging --//
  38.  
  39. require_once 'PEAR.php';
  40. require_once 'HTTP/Session2.php';
  41.  
  42. ini_set('error_reporting'E_ALL);
  43. ini_set('display_errors'1);
  44. //PEAR::setErrorHandling(PEAR_ERROR_DIE);
  45.  
  46. /*
  47. HTTP_Session2::setContainer(
  48.     'DB',
  49.     array(
  50.         'dsn' => 'mysql://root@localhost/database',
  51.         'table' => 'sessiondata'
  52.     )
  53. );
  54. */
  55. HTTP_Session2::start('SessionID'uniqid('MyID'));
  56.  
  57. ?>
  58. <html>
  59. <head>
  60. <style>
  61. body, td {
  62.     font-family: Verdana, Arial, sans-serif;
  63.     font-size: 11px;
  64. }
  65. A:link { color:#003399; text-decoration: none; }
  66. A:visited { color:#6699CC; text-decoration: none; }
  67. A:hover { text-decoration: underline; }
  68. </style>
  69. <title>HTTP Session</title>
  70. </head>
  71. <body style="margin: 5px;">
  72. <?php
  73.  
  74. /*
  75. if (!isset($variable)) {
  76.     $variable = 0;
  77.     echo("The variable wasn't previously set<br>\n");
  78. } else {
  79.     $variable++;
  80.     echo("Yes, it was set already<br>\n");
  81. }
  82. */
  83.  
  84. switch (@$_GET['action']{
  85.     case 'setvariable':
  86.         HTTP_Session2::set('variable''Test string');
  87.         //HTTP_Session2::register('variable');
  88.         break;
  89.     case 'unsetvariable':
  90.         HTTP_Session2::set('variable'null);
  91.         //HTTP_Session2::unregister('variable');
  92.         break;
  93.     case 'clearsession':
  94.         HTTP_Session2::clear();
  95.         break;
  96.     case 'destroysession':
  97.         HTTP_Session2::destroy();
  98.         break;
  99. }
  100.  
  101.  
  102. //echo("session_is_registered('variable'): <b>'" . (session_is_registered('variable') ? "<span style='color: red;'>yes</span>" : "no") . "'</b><br>\n");
  103. //echo("isset(\$GLOBALS['variable']): <b>'" . (isset($GLOBALS['variable']) ? "<span style='color: red;'>yes</span>" : "no") . "'</b><br>\n");
  104.  
  105. echo("------------------------------------------------------------------<br>\n");
  106. echo("Session name: <b>'" HTTP_Session2::name("'</b><br>\n");
  107. echo("Session id: <b>'" HTTP_Session2::id("'</b><br>\n");
  108. echo("Is new session: <b>'" (HTTP_Session2::isNew("<span style='color: red;'>yes</span>" "no""'</b><br>\n");
  109. echo("Is expired: <b>'" (HTTP_Session2::isExpired("<span style='color: red;'>yes</span>" "no""'</b><br>\n");
  110. echo("Is idle: <b>'" (HTTP_Session2::isIdle("<span style='color: red;'>yes</span>" "no""'</b><br>\n");
  111. //echo("Variable: <b>'" . HTTP_Session2::get('variable') . "'</b><br>\n");
  112. echo("Session valid thru: <b>'" (HTTP_Session2::sessionValidThru(time()) "'</b><br>\n");
  113. echo("------------------------------------------------------------------<br>\n");
  114.  
  115. if (HTTP_Session2::isNew()) {
  116.     //HTTP_Session2::set('var', 'value');
  117.     //HTTP_Session2::setLocal('localvar', 'localvalue');
  118.     //blah blah blah
  119. }
  120.  
  121. ?>
  122. <div style="background-color: #F0F0F0; padding: 15px; margin: 5px;">
  123. <pre>
  124. $_SESSION:
  125. <?php
  126. var_dump($_SESSION);
  127. ?>
  128. </pre>
  129. </div>
  130. <?php
  131.  
  132.  
  133. ?>
  134. <p><a href="<?php echo $_SERVER['SCRIPT_NAME'?>?action=setvariable">Set variable</a></p>
  135. <p><a href="<?php echo $_SERVER['SCRIPT_NAME'?>?action=unsetvariable">Unset variable</a></p>
  136. <p><a href="<?php echo $_SERVER['SCRIPT_NAME'?>?action=destroysession">Destroy session</a></p>
  137. <p><a href="<?php echo $_SERVER['SCRIPT_NAME'?>?action=clearsession">Clear session data</a></p>
  138. <p><a href="<?php echo $_SERVER['SCRIPT_NAME'?>">Reload page</a></p>
  139. </body>
  140. </html>

Documentation generated on Mon, 11 Mar 2019 15:37:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.