改进request类的token方法

This commit is contained in:
thinkphp
2016-08-15 11:31:54 +08:00
parent cda05b5595
commit 03ec96c7f9

View File

@@ -1409,13 +1409,13 @@ class Request
* 生成请求令牌 * 生成请求令牌
* @access public * @access public
* @param string $name 令牌名称 * @param string $name 令牌名称
* @param string $type 令牌生成类型 * @param string|array $type 令牌生成方法
* @return string * @return string
*/ */
public function token($name = '__token__', $type = 'md5') public function token($name = '__token__', $type = 'md5')
{ {
$type = is_callable($type) ? $type : 'md5'; $type = is_callable($type) ? $type : 'md5';
$token = $type($_SERVER['REQUEST_TIME_FLOAT']); $token = call_user_func($type, $_SERVER['REQUEST_TIME_FLOAT']);
Session::set($name, $token); Session::set($name, $token);
return $token; return $token;