Added Canvas 1.1.0, originally not under SCM so no historical development records...
[canvas.git] / library / Session.php
blobf0f63720372386ebdee0280b498c3fb676c95dcc
1 <?php
2 // @title Session class
3 // @author Matt Todd <matt@matttoddphoto.com>
4 // @created 2005-09-26
5 // @desc A session class for easily accessing and administering sessions (can
6 // transparently keep all session data in the database)
7 // @requires stdexception.php (StdException class)
9 include_once('stdexception.php');
11 // constants
12 // hash type constants
13 // define("AUTH_HASHTYPE_SHA", 2);
14 // define("AUTH_HASHTYPE_MD5", 5);
16 // classes
17 class Session {
18 // protected variables
19 private $strSID; // the session ID
21 // retreive an instance of the Session object (not a singleton, more of a factory of sorts)
22 public static function retreive() {
23 return new Session();
26 // initialize
27 public static function initialize() {
28 // session_id("thehub"); // must be unique
29 session_name("thehub");
30 session_start();
32 public static function flush() {
33 session_write_close();
35 public static function destroy() {
36 $_SESSION = array(); // empty session
37 setcookie(session_name(), '', time()-42000, '/'); // destroys associated session cookie
38 unset($_COOKIE[session_name()]); // just in case
39 session_destroy(); // destroys the session
40 session_start(); // overwrite it, yeah!
42 return true;
45 public static function flash() {
46 if(empty($_SESSION['flash'])) {
47 return null;
48 } else {
49 $flash = $_SESSION['flash'];
50 $_SESSION['flash'] = null;
51 return $flash;
54 public static function continue_to($url) {
55 $_SESSION['continue_to'] = $url;
58 // functions
59 public function __set($name, $value) {
60 // setcookie($name, $value->username, (15 * 60), ".clayton.edu", "/");
61 $_SESSION[$name] = $value;
63 public function __get($name) {
64 return $_SESSION[$name];
67 // descructor
68 public function __destruct() {
69 // possibly put some serialization code in here?
70 // end;
74 class SessionException extends StdException {