示例#1
0
文件: cookie.php 项目: sd-studio/or
/**
	@param $expireMin  expire time in minutes, also can be 'never'
*/
function set($name, $expireMin = 0, $params = array(), $path = '/')
{
    if ($expireMin == 'never') {
        $expireMin = 60 * 24 * 365 * 10;
    }
    $cookie = new \cf\Cookie($name, $expireMin, $path);
    foreach ($params as $nm => $val) {
        $cookie->setParam($nm, $val);
    }
    $cookie->set();
}
示例#2
0
文件: cart.php 项目: sd-studio/sh
function create()
{
    global $db;
    $user = \cf\User::getLoggedIn();
    if ($user) {
        $cartId = \cf\query2var('SELECT id FROM cf_cart WHERE user_id=:uid', array('uid' => $user->id()));
        if (!$cartId) {
            \cf\execQuery('INSERT INTO cf_cart (user_id) VALUES(:uid)', array('uid' => $user->id()));
            $cartId = $db->lastInsertId();
        }
        if (!\cf\query2var('SELECT COUNT(*) FROM cf_products_in_cart WHERE cart_id=:cid', array('cid' => $cartId))) {
            //the cart is empty check if there is a cart cookie
        }
        return $cartId;
    } else {
        $c = \cf\Cookie::retrieve('cyberfish_cart');
        if (!$c) {
            $c = new \cf\Cookie('cyberfish_cart', 60 * 24 * 365);
            $c->setParam('ready', array());
            $c->set();
        }
        return $c;
    }
}