* @since 1.1.0.0 * @package Mammut\Protocol */ class Header extends \Mammut\StrictObject { private $headers = array(); /** * Add a new header to the object * * @param string $data * the headerdata the header data * @param boolean $replace * replace existing header * @param int $code * a HTTP status code */ public function addHeader($data, $replace = true, $code = false) { $this->headers[] = array($data,$replace,$code); } /** * Add a cookie to the header * * @param mixed $name * name of the cookie * @param mixed $value * content of the cookie * @param number $expires * end of life timestamp of the cookie (0 = end of session, default) * @param string $path * server path of the cookie (default: /) * @param string $domain * valid cookie domains * @param boolean $secure * only send cookie on secure connection * @param boolean $httponly * mark the cookie as a HTTP only cookie (can block CSFR */ public function addCookie($name, $value = '', $expires = 0, $path = '', $domain = '', $secure = false, $httponly = false) { $st = self::cookieString($name, $value, $expires, $path, $domain, $secure, $httponly); $this->addHeader($st); } public function sendHeader() { foreach($this->headers as $header) header($header[0], $header[1], $header[2]); } public static function cookieString($name, $value = '', $expires = 0, $path = '', $domain = '', $secure = false, $httponly = false) { $st = 'Set-Cookie: '; $st .= rawurlencode($name) . '=' . rawurlencode($value); $st .= (empty($expires) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s', $expires) . ' GMT'); $st .= (empty($path) ? '' : '; path=' . $path); $st .= (empty($domain) ? '' : '; domain=' . $domain); $st .= (!$secure ? '' : '; secure'); $st .= (!$httponly ? '' : '; HttpOnly'); return $st; } }