summaryrefslogtreecommitdiffstats
path: root/system/classes/session.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/classes/session.php')
-rw-r--r--system/classes/session.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/system/classes/session.php b/system/classes/session.php
new file mode 100644
index 0000000..963aa9c
--- /dev/null
+++ b/system/classes/session.php
@@ -0,0 +1,57 @@
+<?php
+
+/**
+ * Simple class for accessing session data
+ */
+class Session{
+
+ /**
+ * Flag to check if the session was already intialized
+ * @var boolean
+ * @access private
+ * @static
+ */
+ private static $initialized=false;
+
+ /**
+ * Makes sure the session is initialized
+ *
+ * @return void
+ * @access private
+ * @static
+ */
+ private static function check(){
+ if(!Session::$initialized){
+ session_start();
+ Session::$initialized=true;
+ }
+ }
+
+ /**
+ * Gets a session variable
+ *
+ * @param string $key Variable name
+ * @param mixed $default Default value
+ * @return mixed Session value
+ * @access public
+ * @static
+ */
+ public static function get($key, $default = null) {
+ Session::check();
+ return Misc::arr($_SESSION,$key,$default);
+ }
+
+ /**
+ * Sets a session variable
+ *
+ * @param string $key Variable name
+ * @param mixed $val Variable value
+ * @return void
+ * @access public
+ * @static
+ */
+ public static function set($key, $val) {
+ Session::check();
+ $_SESSION[$key]=$val;
+ }
+} \ No newline at end of file