Ejemplo n.º 1
0
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);
ini_set('session.cookie_lifetime', 10);
register_shutdown_function(array('MySession', 'shutdown_handler'));
MySession::my_session_start();
if (isset($_GET['clear'])) {
    $_SESSION = array();
}
#shutdown_handler();
#echo 'Session ID: ' . session_id() . '<br>';
#var_dump($_SESSION);
#echo '<br>';
#var_dump($_COOKIE);
#var_dump(ini_get('session.use_cookies'));
class MySession
{
    protected static $sessionStarted = false;
    public static function my_session_start()
    {
        if (isset($_COOKIE[ini_get('session.name')])) {
            if (!self::$sessionStarted) {
                session_start();
                #echo 'Session cookie found, started session<br>';
                self::$sessionStarted = true;
                return true;
            }
        } else {
            $_SESSION['foo'] = date('H:i:s');
            return false;