Source for file keep-defs.php

Documentation is available at keep-defs.php

  1. <?php
  2. /* ******************************************************************** */
  3. /* CATALYST PHP Source Code */
  4. /* -------------------------------------------------------------------- */
  5. /* This program is free software; you can redistribute it and/or modify */
  6. /* it under the terms of the GNU General Public License as published by */
  7. /* the Free Software Foundation; either version 2 of the License, or */
  8. /* (at your option) any later version. */
  9. /* */
  10. /* This program is distributed in the hope that it will be useful, */
  11. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  12. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  13. /* GNU General Public License for more details. */
  14. /* */
  15. /* You should have received a copy of the GNU General Public License */
  16. /* along with this program; if not, write to: */
  17. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  18. /* Boston, MA 02111-1307 USA */
  19. /* -------------------------------------------------------------------- */
  20. /* */
  21. /* Filename: keep-defs.php */
  22. /* Author: Paul Waite */
  23. /* Description: Definitions for a 'keep' which guards the values of */
  24. /* variables for a session. This currently uses the PHP */
  25. /* 'session' handling to achieve this. */
  26. /* */
  27. /* NB: This assumes 'track_vars' and 'register_globals' */
  28. /* are set to 'On' in php.ini. */
  29. /* ('register_globals' is the newer name, but in older */
  30. /* versions of php, it was called 'gpc_globals'). */
  31. /* */
  32. /* ******************************************************************** */
  33. /** @package core *//**
  34. * Keep class
  35. * A simple class for remembering variables or forgetting
  36. * them using the PHP session handling routines..
  37. * @package core
  38. */
  39. class keep {
  40. /** The name of the cookie to use
  41. @access private */
  42. var $cookiename = "";
  43. // ....................................................................
  44. /**
  45. * Constructor
  46. * Create a new keep object. Sets basic field attributes.
  47. * @param string $name The name of the keep. This is used as the cookie name.
  48. * @param integer $expiresecs Lifetime of the keep cookie
  49. */
  50. function keep($name="SESSIONKEEP", $expiresecs=0) {
  51. global $RESPONSE;
  52. $this->cookiename = $name;
  53. session_name($name);
  54. if (isset($RESPONSE)) {
  55. session_set_cookie_params($expiresecs, "/", $RESPONSE->http_host);
  56. }
  57. else {
  58. session_set_cookie_params($expiresecs);
  59. }
  60. session_start();
  61. } // keep
  62. // ....................................................................
  63. /**
  64. * Remember variable names
  65. * Register the given comma-delimited list of varnames
  66. * in the current session..
  67. * @param string $varnames A list of comma-delimited var names to remember in the keep
  68. */
  69. function remember($varnames) {
  70. $allvars = explode(",", $varnames);
  71. foreach ($allvars as $var) {
  72. global $$var;
  73. if (!isset($$var)) $$var = "";
  74. if (!session_is_registered($var)) {
  75. debugbr("session keep variable '$var' registered");
  76. session_register($var);
  77. }
  78. }
  79. } // remember
  80. // ....................................................................
  81. /**
  82. * Forget variable names
  83. * Un-register the given comma-delimited list of varnames
  84. * in the current session..
  85. * @param string $varnames A list of comma-delimited var names to forget from the keep
  86. */
  87. function forget($varnames) {
  88. $allvars = explode(",", $varnames);
  89. foreach ($allvars as $var) {
  90. global $$var;
  91. if (session_is_registered($var)) {
  92. session_unregister($var);
  93. }
  94. }
  95. } // forget
  96. // ....................................................................
  97. /**
  98. * Unset all registered variables.
  99. */
  100. function forgetall() {
  101. session_unset();
  102. } // forgetall
  103. // ....................................................................
  104. /**
  105. * Delete registered variables.
  106. * Unset all vars, and delete the session cookie.
  107. */
  108. function delete() {
  109. //$this->forgetall();
  110. setcookie($this->cookiename, "", time() - 3600);
  111. } // delete
  112.  
  113. } // keep class
  114. // ----------------------------------------------------------------------
  115.  
  116. ?>

Documentation generated by phpDocumentor 1.3.0RC3