File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/api/class.session.php
<?php
/**
* This file contains the iwp_session class
*
* @version $Id$
*
*
* @package IWP
* @subpackage IWP_API
*/
/**
* Session Class
* This is a static class. It is used when dealing with session variables.
* It uses a unique key to store everything in so the data is not accessible by a different application or by a IWP in another diretory **
*
* @package IWP
* @subpackage IWP_API
*/
class iwp_session {
/**
* Instance
* This static variable holds the current instance of this object being loaded.
* So using the getInstance function anywhere will return the very same instance.
*
* @var iwp_session Instance
*/
public static $Instance;
/**
* getInstance
* This is a static function that sets up the class instance and stores it to the static variable. It will then return that instantiation in the future.
*
* @return iwp_session Returns the instantiated object
**/
public static function getInstance(){
if(!isset(self::$Instance)){
self::$Instance = new self();
}
return self::$Instance;
}
/**
* This is the key that is used to store the data. It should be a unique key set for this website.
*
* @var string
*/
static private $SessionKey = null;
/**
* This function creates the session and does any other processes needed when intializing. This needs to be explicitly called, it is not called by a constructor.
*
* @return void Doesn't return anything.
*/
public static function start($sessionId=null){
// Setting the timeout to 0
session_set_cookie_params(0);
if(!is_null($sessionId)) {
session_id($sessionId);
session_start();
} else {
session_start();
}
}
function console_log($err){
if(is_array($err)){
ob_start();
print_r($err);
$err = ob_get_contents();
ob_end_clean();
}
if(is_bool($err)){
if($err === true) {
$err = "true";
} else {
$err = "false";
}
}
$err = $err ."\n\n";
file_put_contents(dirname(dirname(__FILE__)). '/tmp/log.txt', $err, FILE_APPEND);
}
/**
* Sets variables through a name/value pair
*
* @param string $name The name of the variable
* @param string $value The value of the variable
*
* @return void Doesn't return anything.
*/
public static function Set($name, $value){
$_SESSION[self::$SessionKey][$name] = $value;
}
/**
* Gets the value of a session variable by its name
*
* @param string $name The name of the variable to retrieve
*
* @return mixed The value of the stored session variable
*/
public static function Get($name=null){
if(isset($_SESSION[self::$SessionKey][$name])){
return $_SESSION[self::$SessionKey][$name];
}
return false;
}
/**
* Deletes a session variable via its key/name
*
* @param string $name The name of the variable to delete
*
* @return void Doesn't return anything.
*/
public static function Kill($name){
$_SESSION[self::$SessionKey][$name] = '';
unset($_SESSION[self::$SessionKey][$name]);
}
/**
* Checks to see if a specified session variable exists
*
* @param string $name The name of the variable to check exists
*
* @return boolean True if the variable exists, false otherwise
*/
public static function Exists($name=null){
if(isset($_SESSION[self::$SessionKey][$name])){
return true;
}else{
return false;
}
}
/**
* This function sets the unique key used by the class for storing the session variables
*
* @param string $key The unique key used -- must only be alplha numeric charaters (a md5 hash is perfect)
*
* @return void Doesn't return anything.
*
* @see $SessionKey
*/
public static function SetKey($key){
self::$SessionKey = iwp_validation::FilterAlphaNumeric($key);
}
/**
* Returns the current session key.
*
* @return string The current session key.
*/
public static function GetKey () {
return self::$SessionKey;
}
}