public static getService ( string $name = '' ) : string | ||
$name | string | SERVER的键值名称 |
return | string |
public static function getService($name = '')
{
if ($name == '') {
return $_SERVER;
}
return isset($_SERVER[$name]) ? strip_tags($_SERVER[$name]) : '';
}
/** * 类加载-设置全局TOKEN,防止CSRF攻击 * * @return void */ public static function setToken() { if (!isset($_COOKIE['CML_TOKEN']) || empty($_COOKIE['CML_TOKEN'])) { $str = substr(md5(Cml::$nowTime . Request::getService('HTTP_USER_AGENT')), 5, 8); setcookie('CML_TOKEN', $str, null, '/'); $_COOKIE['CML_TOKEN'] = $str; } }