Пример #1
0
 public function __construct($namespace, $ttl = 3600)
 {
     $ns = 'thin_' . $namespace;
     $c = cookies()->{$ns};
     if (null === $c) {
         setcookie($ns, Utils::token(), strtotime('+1 year'));
     } else {
         setcookie($ns, $c, strtotime('+1 year'));
     }
     $key = cookies()->{$ns};
     $this->__namespace = $namespace . '::' . $key;
     $this->__ttl = $ttl;
     $this->__db = redisDB::instance('core', 'session');
     $this->clean();
     $this->populate();
 }
Пример #2
0
 public function __construct($ns, $store = 'Thin\\Store')
 {
     $ns = 'thin_' . $ns;
     $c = cookies()->{$ns};
     if (null === $c) {
         setcookie($ns, Utils::token(), strtotime('+1 year'));
     } else {
         setcookie($ns, $c, strtotime('+1 year'));
     }
     $this->key = cookies()->{$ns};
     if (empty($this->key)) {
         throw new Exception("Cookies must be functional to execute this class.");
     }
     $this->model($ns);
     $this->db = new $store('thin_forever_' . $ns);
     $this->fetch();
 }
Пример #3
0
<?php

function cookies()
{
    echo "i ate" . "" . " cookies <br>";
}
cookies();
?>



<?php 
$name = "Henk.";
function sayHello()
{
    global $name;
    echo "My name is:" . "" . " {$name}";
}
sayHello();
Пример #4
0
$_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
$_SERVER['HTTP_X_AUTH_TOKEN'] = 'some-token';
assert(headers('content-length') === 1024);
assert(headers('content-type') === 'application/x-www-form-urlencoded');
assert(headers('x-auth-token') === 'some-token');
if (function_exists('xdebug_get_headers')) {
    # test header setting
    headers('x-powered-by', 'dispatch', true);
    headers('x-authored-by', 'noodlehaus', true);
    assert(headers_get_clean() === ['x-powered-by: dispatch', 'x-authored-by: noodlehaus']);
    # cookie fetch
    $_COOKIE = ['name' => 'dispatch'];
    assert(cookies('name') === 'dispatch');
    assert(cookies('invalid') === null);
    # cookie set
    cookies('title', 'john & marsha', time() + 3600, '/');
    assert(strpos(headers_get_clean()[0], 'Set-Cookie: title=john+%26+marsha; expires=') === 0);
    # json response
    ob_start();
    json(['name' => 'dispatch']);
    assert(ob_get_clean() === json_encode(['name' => 'dispatch']));
    assert(strpos(headers_get_clean()[0], 'Content-type: application/json') === 0);
    # no-cache headers
    ob_start();
    nocache('dispatch');
    ob_get_clean();
    $list = headers_get_clean();
    assert($list[0] === 'Expires: Tue, 13 Mar 1979 18:00:00 GMT');
    assert(strpos($list[1], 'Last-Modified: ') === 0);
    assert($list[2] === 'Cache-Control: no-store, no-cache, must-revalidate');
    assert($list[3] === 'Cache-Control: post-check=0, pre-check=0');