bludit/kernel/helpers/session.class.php

74 lines
1.4 KiB
PHP
Raw Normal View History

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"],
2015-05-15 00:07:45 +02:00
$cookieParams["path"],
$cookieParams["domain"],
2015-05-05 03:00:01 +02:00
$secure,
$httponly
);
// Sets the session name to the one set above.
session_name($session_name);
2015-05-15 00:07:45 +02:00
2015-05-05 03:00:01 +02:00
// 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);
2015-05-15 00:07:45 +02:00
2015-03-27 02:00:01 +01:00
self::$started = false;
2015-05-15 00:07:45 +02:00
return !isset($_SESSION);
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;
2015-05-15 00:07:45 +02:00
2015-03-27 02:00:01 +01:00
$_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;
}
}