ID: ded267d185a580db18ff6d13359cd14d96923a76
69 lines
—
2K —
View raw
| <?php
session_name ('freepost');
session_start ();
class Session {
public static function is_valid ()
{
return isset ($_SESSION) && !is_null ($_SESSION) && !empty ($_SESSION);
}
public static function get_user ()
{
if (self::is_valid ())
return $_SESSION['user'];
else
return NULL;
}
public static function get_username ()
{
if (self::is_valid ())
return $_SESSION['user']['name'];
else
return '';
}
public static function get_userid ()
{
if (self::is_valid ())
return $_SESSION['user']['id'];
else
return '';
}
/**
* Set user information to the session
*
* @param user Associative array of user properties
*/
public static function set ($user)
{
$_SESSION = array (
'user' => array (
'id' => $user['id'],
'hash_id' => $user['hashId'],
'email' => $user['email'],
'registered' => $user['registered'],
'name' => $user['username'],
'about' => $user['about']));
}
/**
* Set user information to the session.
* This is like "set ($user)", but instead of $user we are given
* a single property.
*/
public static function set_property ($property, $value)
{
$_SESSION['user'][$property] = $value;
}
public static function delete ()
{
unset ($_SESSION);
session_destroy ();
$_SESSION = NULL;
}
}
|