Exemplo n.º 1
0
 /**
  * Get value of HTTP cookie from the current HTTP request
  *
  * Return the value of a cookie from the current HTTP request,
  * or return NULL if cookie does not exist. Cookies created during
  * the current request will not be available until the next request.
  *
  * @param  string      $name
  * @param  bool        $deleteIfInvalid doing delete if invalid
  * @param  bool        $encrypted       use force encryped to set true if encrypted
  *                                      without following config
  *                                      set to false if use no encryption
  * @return string|null
  */
 public static function get($name, $deleteIfInvalid = false, $encrypted = null)
 {
     // Get cookie value
     $cookies = Request::cookies();
     $value = $cookies->get($name);
     $config = Config::singleton();
     $prefix = $config->get('cookie_encrypt_prefix', 'enc|');
     is_string($prefix) && trim($prefix) || ($prefix = 'enc|');
     // Decode if encrypted
     if (($config->get('cookie_encrypt', true) && $encrypted !== false || $encrypted) && strpos($value, $prefix) === 0) {
         $value = Security::decrypt($value, sha1($config->security_key . $config->security_salt . $config->session_hash));
         if ($value === null && $deleteIfInvalid) {
             static::deleteCookie($name);
         }
     }
     return $value;
 }