2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
class Session {
|
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
private static $started = false;
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
public static function start()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-03-27 02:00:01 +01:00
|
|
|
if(self::$started)
|
|
|
|
return true;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
|
|
|
// DEBUG: Ver un nombre con alguna llave random al momentode instalar.
|
|
|
|
$session_name = 'Bludit-KEY';
|
|
|
|
|
|
|
|
// If TRUE cookie will only be sent over secure connections.
|
|
|
|
$secure = false;
|
|
|
|
|
|
|
|
// If set to TRUE then PHP will attempt to send the httponly flag when setting the session cookie.
|
|
|
|
$httponly = true;
|
|
|
|
|
|
|
|
// Gets current cookies params.
|
|
|
|
$cookieParams = session_get_cookie_params();
|
|
|
|
|
|
|
|
session_set_cookie_params($cookieParams["lifetime"],
|
|
|
|
$cookieParams["path"],
|
|
|
|
$cookieParams["domain"],
|
|
|
|
$secure,
|
|
|
|
$httponly
|
|
|
|
);
|
|
|
|
|
|
|
|
// Sets the session name to the one set above.
|
|
|
|
session_name($session_name);
|
|
|
|
|
|
|
|
// Start session.
|
|
|
|
self::$started = session_start();
|
|
|
|
|
|
|
|
// Regenerated the session, delete the old one. There are problems with AJAX.
|
|
|
|
//session_regenerate_id(true);
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
public static function started()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-03-27 02:00:01 +01:00
|
|
|
return self::$started;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
public static function destroy()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-03-27 02:00:01 +01:00
|
|
|
session_destroy();
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
unset($_SESSION);
|
|
|
|
|
|
|
|
self::$started = false;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
public static function set($key, $value)
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-03-27 02:00:01 +01:00
|
|
|
$key = 's_'.$key;
|
|
|
|
|
|
|
|
$_SESSION[$key] = $value;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
public static function get($key)
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-03-27 02:00:01 +01:00
|
|
|
$key = 's_'.$key;
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-03-27 02:00:01 +01:00
|
|
|
if( isset($_SESSION[$key]) )
|
|
|
|
return $_SESSION[$key];
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|