ct_dbm.inc
上传用户:xuanqunsh
上传日期:2007-01-04
资源大小:58k
文件大小:2k
源码类别:

WEB邮件程序

开发平台:

PHP

  1. <?php
  2. ##
  3. ## Copyright (c) 1999 Daniel Lashua <daniel.lashua@gte.com>
  4. ##
  5. ## $Id: ct_dbm.inc,v 1.1 2000/04/12 23:23:20 prenagha Exp $
  6. ##
  7. ## PHPLIB Data Storage Container using DBM Files
  8. ##
  9. ## Code inspired by ct_shm.inc v 1.1 
  10. class CT_DBM {
  11. ##
  12. ## Define these parameters by overwriting or by
  13. ## deriving your own class from it (recommened)
  14. ##
  15. var $dbm_file = "";    ## PREEXISTING DBM File 
  16.        ## writable by the web server UID
  17. ## end of configuration
  18. var $dbmid;        ## our dbm resource handle
  19. function ac_start() {
  20. # Open DBM file for write access
  21. $this->dbmid = dbmopen($this->dbm_file, "w");
  22.     if (!$this->dbmid) {
  23.       $this->ac_halt("Failed to open dbm in ac_start()");
  24.     }
  25. }
  26. function ac_get_lock() {
  27. # Not needed in this instance
  28. }
  29. function ac_release_lock() {
  30. # Not needed in this instance
  31. }
  32. function ac_newid($str, $name) {
  33. return $str;
  34. }
  35. function ac_store($id, $name, $str) {
  36. dbmreplace($this->dbmid, "$id$name", base64_encode($str).";".time());
  37. return true;
  38. }
  39. function ac_delete($id, $name) {
  40. dbmdelete($this->dbmid, "$id$name");
  41. }
  42. function ac_gc($gc_time, $name) {
  43. $cmp = time() - $gc_time * 60;
  44. $i = dbmfirstkey($this->dbmid);
  45. while ($i) {
  46. $val = @dbmfetch($this->dbmid, $i);
  47. $dat = explode(";", $val);
  48. if(strcmp($dat[1], $cmp) < 0) {
  49. dbmdelete($this->dbmid, $i);
  50. }
  51. $i = dbmnextkey($this->dbmid,$i);
  52. }
  53. }
  54. function ac_halt($s) {
  55. echo "<p>ERROR in ct_dbm.inc<br><b>$s</b>";
  56. exit;
  57. }
  58. function ac_get_value($id, $name) {
  59. $dat = explode(";", dbmfetch($this->dbmid, "$id$name"));
  60. return base64_decode($dat[0]);
  61. }
  62. function ac_dump() {
  63.     print("<hr><b>Session Data Dump:</b>");
  64.     print("<br>dblist: " . dblist());
  65.     print("<table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#CCCCCC>n");
  66.     print("<tr><th>key</th><th>value</th><th>time</th></tr>n");
  67. $i = dbmfirstkey($this->dbmid);
  68. while ($i) {
  69. $val = @dbmfetch($this->dbmid, $i);
  70. $dat = explode(";", $val);
  71.       printf("<tr valign=top><td><small>%s</small></td><td><small>%s</small></td><td><small>%s</small></td></tr>n", $i, ereg_replace(";", ";<br>", (base64_decode($dat[0]))), $dat[1]);
  72. $i = dbmnextkey($this->dbmid,$i);
  73. }
  74.     print("</table><hr>n");
  75. }
  76. }
  77. ?>