Advertisement
Guest User

Havenard

a guest
Sep 8th, 2009
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?
  2.  
  3.     class mySession {
  4.         var $path = 'C:\\WINDOWS\\TEMP'; // define the folder to save the sessions cache
  5.         var $id = '';
  6.         var $fd = NULL;
  7.         function __construct($id = '') {
  8.             global $_MYSESSION;
  9.             $this->id = $_COOKIE['MYSESSION'];
  10.             if (empty($this->id) || !eregi('^[a-f0-9]{32}$', $this->id) || ($this->id != md5($id))) {
  11.                 if (empty($id)) {
  12.                     $i = 1;
  13.                     do {
  14.                         $this->id = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . microtime() . $i++);
  15.                     } while (file_exists("{$this->path}/MYSESSION{$this->id}"));
  16.                 }
  17.                 else {
  18.                     $this->id = md5($id);
  19.                 }
  20.                 header("Set-Cookie: MYSESSION={$this->id}");
  21.             }
  22.             $this->path = "{$this->path}/MYSESSION{$this->id}";
  23.             @ $_MYSESSION = unserialize(file_get_contents($this->path));
  24.             @ $this->fd = fopen($this->path, 'w');
  25.             while (!$this->fd) {
  26.                 sleep(10);
  27.                 @ $this->fd = fopen($this->path, 'w');
  28.             }
  29.         }
  30.         function __destruct() {
  31.             global $_MYSESSION;
  32.             fwrite($this->fd, serialize($_MYSESSION));
  33.             fclose($this->fd);
  34.         }
  35.     }
  36.     new mySession();
  37.  
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement