/** * @param Response $response * @return Response */ public function logout(Response $response) { if ($this->isAuthenticated()) { $this->_cookies->set("session_token", ["value" => "", "expires" => time() - 3600]); $this->getUser()->storeRememberToken(null); $this->_user = null; $this->_authenticated = false; return $response->withHeader('Set-Cookie', $this->_cookies->toHeaders()); } return $response; }
/** * DEPRECATION WARNING! Access `cookies` property directly. * * Set cookie * * Instead of using PHP's `setcookie()` function, Slim manually constructs the HTTP `Set-Cookie` * header on its own and delegates this responsibility to the `Slim_Http_Util` class. This * response's header is passed by reference to the utility class and is directly modified. By not * relying on PHP's native implementation, Slim allows middleware the opportunity to massage or * analyze the raw header before the response is ultimately delivered to the HTTP client. * * @param string $name The name of the cookie * @param string|array $value If string, the value of cookie; if array, properties for * cookie including: value, expire, path, domain, secure, httponly */ public function setCookie($name, $value) { // Util::setCookieHeader($this->header, $name, $value); $this->cookies->set($name, $value); }
/** * Set response cookie * * @param string $name Cookie name * @param string|array $value Cookie value, or cookie properties * @param string|int $expires [optional] Cookie expire value * * @return $this */ public function set($name, $value, $expires = null) { $name = $this->getFullName($name); if (!is_array($value)) { $value = ['value' => (string) $value]; } if (isset($expires)) { $value['expires'] = $expires; } parent::set($name, $value); return $this; }