/** * 初步过滤用户通过http提交的数据 * 并销毁全局数组 消除不安全因素 * @param Cookie $cookie cookie对象 */ public function __construct($cookie) { $pattern = '/^[a-z0-1-_\\.]+$/i'; foreach (array('get', 'post', 'cookie', 'files') as $data) { $inputData = '_' . strtoupper($data); foreach ($GLOBALS[$inputData] as $key => $val) { if (preg_match($pattern, $key)) { $tmp =& $this->{$data}; $tmp[$key] = $val; } } unset($GLOBALS[$inputData]); } $cookie->init($this->cookie); $this->cookie = $cookie; }
public static function cookie() { Lib::load('cookie'); return Cookie::init(); }
public static function cookie() { Lib::load('cookie'); $cookie = Cookie::init(); $totalArgs = func_num_args(); $arguments = func_get_args(); if ($totalArgs === 1) { return $cookie->get($arguments[0]); } if ($totalArgs === 2) { if ($arguments[1] === null) { return $cookie->delete($arguments[0]); } return $cookie->set($arguments[0], $arguments[1]); } return $cookie; }
return mcrypt_encrypt(self::$cipher, self::$salt, $value . "@" . self::$user_angent, self::$mode, $iv); } public static function init() { self::$user_angent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "No User Agent"; self::$salt = $GLOBALS['config']['cookie']; self::$expiration = 0; self::$parts = 2; self::$mode = MCRYPT_MODE_ECB; self::$cipher = MCRYPT_DES; } /** * 删除 Cookie * * @param string $key */ public static function delete($key) { $key = self::hashKey($key); $cname = str_split($key, ceil(strlen($key) / self::$parts)); for ($i = 0; $i < self::$parts; $i++) { setcookie($cname[$i], null, time() - 3600); } } private static function hashKey($key) { return md5($key); } } Cookie::init();