示例#1
0
 /**
  * Sends a cookie.
  * @param  string name of the cookie
  * @param  string value
  * @param  string|int|\DateTimeInterface  expiration time, value 0 means "until the browser is closed"
  * @param  string
  * @param  string
  * @param  bool
  * @param  bool
  * @return self
  * @throws Nette\InvalidStateException  if HTTP headers have been sent
  */
 public function setCookie($name, $value, $time, $path = NULL, $domain = NULL, $secure = NULL, $httpOnly = NULL)
 {
     self::checkHeaders();
     setcookie($name, $value, $time ? (int) DateTime::from($time)->format('U') : 0, $path === NULL ? $this->cookiePath : (string) $path, $domain === NULL ? $this->cookieDomain : (string) $domain, $secure === NULL ? $this->cookieSecure : (bool) $secure, $httpOnly === NULL ? $this->cookieHttpOnly : (bool) $httpOnly);
     Helpers::removeDuplicateCookies();
     return $this;
 }
示例#2
0
 /**
  * Regenerates the session ID.
  * @throws Nette\InvalidStateException
  * @return void
  */
 public function regenerateId()
 {
     if (self::$started && !$this->regenerated) {
         if (headers_sent($file, $line)) {
             throw new Nette\InvalidStateException("Cannot regenerate session ID after HTTP headers have been sent" . ($file ? " (output started at {$file}:{$line})." : "."));
         }
         session_regenerate_id(TRUE);
         session_write_close();
         $backup = $_SESSION;
         session_start();
         $_SESSION = $backup;
         Helpers::removeDuplicateCookies();
     }
     $this->regenerated = TRUE;
 }