Source for file User.class.php
Documentation is available at User.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @desc User Session Class
gumbo_load ("Interface_Session_User");
gumbo_load ("Session_Encrypt");
/** @var string $_user_key SESSION key name for User data */
/** @var int|string$_user_id User ID */
/** @var boolean $_user_loaded if user was successfully loaded */
* @param string $user_key SESSION [key] name for User data
* Loads the User SESSION data
* The User Session Encrypted String is saved in the following format:
* session_id||user_id||agent||ip_address||date
* @postcondition setUser ()
* @postcondition _setUserLoaded ([true|false])
* @throws Gumbo_Exception
if (isset
($this->$key) &&
!$this->getUser ()) {
if (count ($data) !=
5) {
foreach ($data as $key=>
$val) {
case 0 :
$id =
$val; break; // Session ID
case 1 :
$user =
$val; break; // User ID
case 2 :
$agent =
$val; break; // $_SERVER ['HTTP_USER_AGENT']
case 3 :
$ip =
long2ip ($val); break; // IP Address $_SERVER ['REMOTE_ADDR']
case 4 :
$date =
new Gumbo_Date ($val); break; // Logged In or Saved Session
// check that Session ID is equal
if ($id !==
$this->getId ()) {
// check that User Agents match
if ($agent !==
$_SERVER ['HTTP_USER_AGENT']) {
throw
new Gumbo_Exception ("User Agent Invalid: {$_SERVER ['HTTP_USER_AGENT']} != {$agent}");
// check that the Session hasn't expired
// check the IP Address, or IP Range is accurate
if ($ip !==
$_SERVER ['REMOTE_ADDR']) {
foreach (explode (".", $ip) as $key=>
$val) {
if ($key ==
2) { break; }
if (substr ($_SERVER ['REMOTE_ADDR'], 0, strlen ($new_ip)) !==
$new_ip) {
throw
new Gumbo_Exception ("Session IP Address Invalid: {$_SERVER ['REMOTE_ADDR']} != {$ip}");
$e->setFunction (__METHOD__
);
* The User Session Encrypted String is saved in the following format:
* session_id||user_id||agent||ip_address||date
* @precondition getUser()
* @throws Gumbo_Exception
$this->$key =
$this->getId () .
"||" .
$this->getUser () .
"||" .
$_SERVER ['HTTP_USER_AGENT'] .
"||" .
$_SERVER ['REMOTE_ADDR'] .
"||" .
$date->get ();
$e->setFunction (__METHOD__
);
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* @param int|string$userID
* @throws Gumbo_Exception
public function setUser ($userID) {
throw
new Gumbo_Exception_InvalidArgument ("userID", $userID, "string|int");
if (is_numeric ($userID)) { $userID = (int)
$userID; }
$e->setFunction (__METHOD__
);
* Sets if the User was properly loaded
* @throws Gumbo_Exception
$e->setFunction (__METHOD__
);
* Returns if the User has been loaded