Example #1
0
 /**
  * 获取Cookie值
  *
  * @param string $key cookie name
  * @param mixed $default default value to return
  * @return string
  */
 public static function get($key, $default = NULL)
 {
     if (!self::$config) {
         self::$config = C('cookie');
     }
     if (!isset($_COOKIE[self::$config['prefix'] . $key])) {
         return $default;
     }
     $cookie = base64_decode($_COOKIE[self::$config['prefix'] . $key]);
     $split = strlen(self::salt($key, NULL));
     if (isset($cookie[$split]) and $cookie[$split] === '~') {
         list($hash, $value) = explode('~', $cookie, 2);
         if (self::salt($key, $value) === $hash) {
             return $value;
         }
         self::delete($key);
     }
     return $default;
 }
Example #2
0
 public function __construct()
 {
     if (null === Cookie::$config) {
         Cookie::$config = Core::config('cookie');
     }
 }
Example #3
0
 function __construct()
 {
     // Getting config elements
     require APP_DIR . 'config/config.php';
     self::$config = $config;
 }