note 69614 deleted from ref.session by felipe

From: Date: Sun, 30 Dec 2007 16:02:24 +0000
Subject: note 69614 deleted from ref.session by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134307@lists.php.net to get a copy of this message
Note Submitter: ---- Here is a replacement I wrote for Session Handeling. Before use, you must replace "[--PATH-TO-SESSION-FOLDER--]" with the path to where sessions should be stored. Make sure to set the proper permissions for that folder :) -------------------------------------------------------------------- <? class Session { function _makeid() { $time = time(); $ip = $_SERVER["REMOTE_ADDR"]; $agent = $_SERVER["HTTP_USER_AGENT"]; $md5 = md5($time.$ip.$agent); setcookie("SClass", $md5); return($md5); } function getid() { $md5 = $_COOKIE['SClass']; return($md5); } function start() { $id = $this->getid(); if (!$id) { $id = $this->_makeid(); } } function _getfile() { $file = $this->getid(); $file .= ".ssn"; $file = "[--PATH-TO-SESSION-FOLDER--]".$file; return($file); } function _setdata($data) { $file = $this->_getfile(); $fs = @fopen($file, w); if ($fs) { fwrite($fs, $data); fclose($fs);} if (!$fs) { return(FALSE); } } function _getdata() { $file = $this->_getfile(); $fs = @fopen($file, 'r'); if ($fs) { $data = fread($fs, filesize($file)); fclose($fs); return $data; } if (!$fs) { return(FALSE); } } function set($key, $value) { $data = $this->_getdata(); $data = base64_decode($data); $array = unserialize($data); $array["$key"] = $value; $newdata = serialize($array); $newdata = base64_encode($newdata); $this->_setdata($newdata); } function get($key) { $data = $this->_getdata(); $data = base64_decode($data); $array = unserialize($data); return($array[$key]); } } ?> -------------------------------------------------------------------- Useage: $Session = new Session(); $Session->start(); $Session->set($key, $value); $sessionvalue = $Session->get($key); -------------------------------------------------------------------- - Jestin S Larson

« previous php.notes (#134307) next »