顺德公农庄 发表于 2017-12-30 06:16:42

[PHP] Phalcon操作示范

// This method does not removes cookies from the _COOKIE superglobal  
// This method overrides any cookie set before with the same name
  
$this->cookies->get('name')->delete();
  

  
// Sets a cookie to be sent at the end of the request
  
$this->cookies->set('name', 'value', time() + $expire, '/', false, 'example.com', true);
  

  
// Sends the cookies to the client.
  
// Cookies aren't sent if headers are sent in the current request
  
$this->cookies->send();
  

  
// Check if a cookie is defined in the bag or exists in the _COOKIE superglobal
  
if ( $this->cookies->has('name') ) {
  

  
// Get the cookie
  
$this->cookies->get('name');
  

  
// Get the cookie's value
  
$this->cookies->get('name')->getValue();
  
}
  

  

  
// By default, cookies are automatically encrypted before being sent to the client and are decrypted when retrieved from the user.
  

  
// Disable encryption in the following way
  
$di->set('cookies', function() {
  
return (new \Phalcon\Http\Response\Cookies())->useEncryption(false);
  
});
  

  
// To use encryption, a global key must be set.
  
$di->set('crypt', function() {
  
return (new \Phalcon\Crypt())->setKey('^YourOwnKey$');
  
});
页: [1]
查看完整版本: [PHP] Phalcon操作示范