/** * Delete HTTP cookie header * * This method will construct and set the HTTP `Set-Cookie` header to invalidate * a client-side HTTP cookie. If a cookie with the same name (and, optionally, domain) * is already set in the HTTP response, it will also be removed. Slim uses this method * instead of PHP's native `setcookie` method. This allows more control of the HTTP header * irrespective of PHP's native implementation's dependency on PHP versions. * * This method accepts the \Slim\Http\Headers object by reference as its * first argument; this method directly modifies this object instead of * returning a value. * * @param \Slim\Interfaces\Http\HeadersInterface $headers * @param string $name * @param array $value * @api */ public function deleteHeader(HeadersInterface &$headers, $name, $value = array()) { $crumbs = $headers->has('Set-Cookie') ? explode("\n", $headers->get('Set-Cookie')) : array(); $cookies = array(); foreach ($crumbs as $crumb) { if (isset($value['domain']) && $value['domain']) { $regex = sprintf('@%s=.*domain=%s@', urlencode($name), preg_quote($value['domain'])); } else { $regex = sprintf('@%s=@', urlencode($name)); } if (preg_match($regex, $crumb) === 0) { $cookies[] = $crumb; } } if (!empty($cookies)) { $headers->set('Set-Cookie', implode("\n", $cookies)); } else { $headers->remove('Set-Cookie'); } $this->setHeader($headers, $name, array_merge(array('value' => '', 'path' => null, 'domain' => null, 'expires' => time() - 100), $value)); }
/** * Redirect * * This method prepares the response object to return an HTTP Redirect response * to the client. * * @param string $url The redirect destination * @param int $status The redirect HTTP status code * @api */ public function redirect($url, $status = 302) { $this->setStatus($status); $this->headers->set('Location', $url); }
/** * Set header value * * @param string $name * @param string $value * @api */ public function setHeader($name, $value) { $this->headers->set($name, $value); }