Code

Added class session.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 3 Jan 2008 13:51:04 +0000 (13:51 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 3 Jan 2008 13:51:04 +0000 (13:51 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8194 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/include/class_session.inc [new file with mode: 0644]

diff --git a/gosa-core/include/class_session.inc b/gosa-core/include/class_session.inc
new file mode 100644 (file)
index 0000000..61154c7
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+/*
+   This code is part of GOsa (https://oss.gonicus.de/labs/gosa/)
+   Copyright (C) 2007 Fabian Hickert
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+class session {
+
+       public static function get_session_size()
+       {
+
+       }
+
+       public static function get_element_size()
+       {
+       
+       }
+
+       public static function is_set($name)
+       {
+               session::log("Checked if element '".$name."' exists. Returned (".isset($_SESSION[$name]).")");
+               return(isset($_SESSION[$name]));
+       }
+
+       public static function set($name,$value)
+       {
+               session::log("Set '".$name."' to '".gettype($value)."'.");
+               $_SESSION[$name] = $value;
+       }
+
+       public static function &get($name)
+       {
+               $ret = FALSE;
+               if(session::is_set($name)){
+                       $ret = $_SESSION[$name];
+                       session::log("Returned '".gettype($ret)."' for '".$name."'.");
+               }else{
+                       session::log("Returned FALSE for '".$name."'. Element wasn't set.");
+               }
+               return($ret);
+       }
+
+       public static function delete($name)
+       {
+               if(session::is_set($name)){
+                       unset($_SESSION[$name]);
+                       session::log("Removed element '".$name."'.");
+               }else{
+                       session::log("Tried to remove element '".$name."'. Element wasn't set.");
+               }
+       }
+
+       public static function un_set($name)
+       {
+               return(session::delete($name));
+       }
+
+       public static function start()
+       {
+               /* Set cookie lifetime to one day (The parameter is in seconds ) */
+               session_set_cookie_params(24*60*60);
+
+               /* Set cache limter to one day (parameter is minute !!)*/
+               session_cache_expire(60*24);  // default is 180
+
+               /* Set session max lifetime, to prevent the garbage collector to delete session before timeout.
+                  !! The garbage collector is a cron job on debian systems, the cronjob will fetch the timeout from
+                  the php.ini, so if you use debian, you must hardcode session.gc_maxlifetime in your php.ini */
+               ini_set("session.gc_maxlifetime",24*60*60);
+               session_start();
+               session::log("Session startet");
+       }
+
+       public static function destroy()
+       {
+               session_destroy();
+       }
+
+       public static function set_lifetime($seconds = -1)
+       {
+               echo "Not implemented yet";
+       }
+
+       private static function log($str)
+       {
+#              echo $str."<br>";
+       }
+
+       public static function &get_all()
+       {
+               session::log("Returned complete session.");
+               return($_SESSION);
+       }
+}
+
+?>