public function set(array $delete, array $cookies) { $pending = array(); $f = function ($spec, $key, $val) use($pending) { if (!array_key_exists($spec, $pending)) { $pending[$spec] = array(); } $pending[$spec][$key] = $val; }; foreach ($delete as $key) { f(null, $key, ''); } foreach ($cookies as $key => $data) { list($val, $spec) = $data; $f($spec, $key, $val); } $callback = $this->callback; foreach ($pending as $spec => $data) { if ($spec === null) { $spec = new CookieSpec(); } $flags = $spec->secure ? extCookie::SECURE : 0; $flags += $spec->httponly ? extCookie::HTTPONLY : 0; $httpCookie = new extCookie(null, $flags); $httpCookie->setCookies($data); $httpCookie->setExpires($spec->expire); $httpCookie->setPath($spec->path); $httpCookie->setDomain($spec->domain); $callback($httpCookie->toString()); } return true; }
/** * Send a cookie without urlencoding the cookie value * * @link http://www.php.net/manual/en/function.setrawcookie.php * * @param string $name The name of the cookie. * @param string $value (optional) The value of the cookie. * @param integer $expire (optional) The time the cookie expires. This is a Unix timestamp * @param string $path (optional) The path on the server in which the cookie will be available on. * @param string $domain (optional) The domain that the cookie is available to. * @param boolean $secure (optional) Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. * @param boolean $secure (optional) When TRUE the cookie will be made accessible only through the HTTP protocol. * @return boolean */ public static final function setrawcookie($name, $value, $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false) { $cookie = new http\Cookie(); $cookie->addCookie($name, $value); $cookie->setExpires($expire); $cookie->setPath($path); $cookie->setDomain($domain); $flags = 0; if ($secure) { $flags = Cookie::SECURE; } if ($httponly) { $flags = $flags | Cookie::HTTPONLY; } $cookie->setFlags($flags); Header::header(sprintf('Set-Cookie: %s', $cookie), false); return true; }
/** * Defines a cookie to be sent along with the rest of the HTTP headers. * * @param string $name The name of the cookie. * @param string $value The value of the cookie. * @param integer $expire (optional) The time the cookie expires. This is a Unix timestamp * @param string $path (optional) The path on the server in which the cookie will be available on. * @param string $domain (optional) The domain that the cookie is available to. * @param boolean $secure (optional) Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. * @param boolean $httpOnly (optional) When TRUE the cookie will be made accessible only through the HTTP protocol. * @return boolean Returns TRUE on success or FALSE on failure. */ public function setCookie($name, $value, $expire = 0, $path = null, $domain = null, $secure = false, $httpOnly = false) { $cookie = new Cookie(); $cookie->addCookie($name, $value); $cookie->setExpires($expire); $cookie->setPath($path); $cookie->setDomain($domain); $flags = 0; if ($secure) { $flags = Cookie::SECURE; } if ($httpOnly) { $flags = $flags | Cookie::HTTPONLY; } $cookie->setFlags($flags); return $this->addHeaders(array('Set-Cookie' => $cookie->toString()), true); }
/** * Sets cookies * * @param array $cookies */ public function setCookies(Cookie $cookies) { $data = $cookies->toArray(); $this->cookies = $data['cookies']; $_COOKIE = $this->cookies; }