Location: PHPKode > projects > ArasPhp Framework > ArasPhp-0.03/core/helpers/Session.php
<?php

/**
 * Session helper
 * Easy management of sessions
 */
 
class Session {

	/**
	* Keeps alive the session when navigating
	* It will load all neccesary classes of objects stored on it
	*/
	public function keepAlive()
	{		
		session_start();
	}
	
	/**
	* Sets the session name
	* @param name
	*/
	public function setName($name)
	{
		session_name($name);
		$_SESSION['sessionName'] = $name;
		
		// We also track an md5 hash of the timestamp and session name
		session::store("sessionIp", $_SERVER['REMOTE_ADDR']);
	}
	
	/**
	* Adds a variable to our session
	*/
	public function store($name, $whatever)
	{
		// We add it
		$_SESSION[$name] = $whatever;
	}
	
	/**
	* Checks if session name is equals to the one provided
	* And also checks if the requester IP is the same that the one saved
	* @param string name
	* @return bool
	*/
	public function checkSession($name)
	{
		if(session_name() == $name 
			&& $_SESSION['sessionIp'] == $_SERVER['REMOTE_ADDR']
			&& $_SESSION['sessionName'] == $name)
		{
			return true;
		}
			
		return false;
	}
	
	/**
	* Destroys the session
	*/
	public function kill()
	{
		foreach($_SESSION as $var)
		{
			unset($var);
		}
		
		session_unset();
	}
 	  
}
 
 ?>
Return current item: ArasPhp Framework