/** * 跳转到上次记住的url */ public function restore() { if (Session::has('redirect_url')) { $this->data = Session::get('redirect_url'); Session::delete('redirect_url'); } }
public function get_id($id) { $arr['msg'] = "this id is " . $id; $arr['id'] = $id; $arr["d"] = a2(5, 14); \think\Session::get("uid", $id); return $arr; }
function session($name, $value = '') { if (is_array($name)) { // 初始化 \think\Session::init($name); } elseif (is_null($name)) { // 清除 \think\Session::clear($value); } elseif ('' === $value) { // 获取 return \think\Session::get($name); } elseif (is_null($value)) { // 删除session return \think\Session::delete($name); } else { // 设置session return \think\Session::set($name, $value); } }
/** * 获取session数据 * @access public * @param string|array $name 数据名称 * @param string $default 默认值 * @param string|array $filter 过滤方法 * @return mixed */ public function session($name = '', $default = null, $filter = null) { if (empty($this->session)) { $this->session = Session::get(); } if (is_array($name)) { return $this->session = array_merge($this->session, $name); } return $this->input($this->session, $name, $default, $filter); }
/** * Session管理 * @param string|array $name session名称,如果为数组表示进行session设置 * @param mixed $value session值 * @param string $prefix 前缀 * @return mixed */ function session($name, $value = '', $prefix = null) { if (is_array($name)) { // 初始化 Session::init($name); } elseif (is_null($name)) { // 清除 Session::clear('' === $value ? null : $value); } elseif ('' === $value) { // 判断或获取 return 0 === strpos($name, '?') ? Session::has(substr($name, 1), $prefix) : Session::get($name, $prefix); } elseif (is_null($value)) { // 删除 return Session::delete($name, $prefix); } else { // 设置 return Session::set($name, $value, $prefix); } }
/** * 验证表单令牌 * @access protected * @param mixed $value 字段值 * @param mixed $rule 验证规则 * @param array $data 数据 * @return bool */ protected function token($value, $rule, $data) { $rule = !empty($rule) ? $rule : '__token__'; if (!isset($data[$rule]) || !Session::has($rule)) { // 令牌数据无效 return false; } // 令牌验证 if (isset($data[$rule]) && Session::get($rule) === $data[$rule]) { // 防止重复提交 Session::delete($rule); // 验证完成销毁session return true; } // 开启TOKEN重置 Session::delete($rule); return false; }
/** * @covers think\Session::get * * @todo Implement testGet(). */ public function testGet() { \think\Session::prefix(null); \think\Session::set('sessionnameget', 'sessionvalue'); $this->assertEquals(\think\Session::get('sessionnameget'), $_SESSION['sessionnameget']); \think\Session::set('sessionnamegetarr.subname', 'sessionvalue'); $this->assertEquals(\think\Session::get('sessionnamegetarr.subname'), $_SESSION['sessionnamegetarr']['subname']); \think\Session::set('sessionnamegetarrperall', 'sessionvalue', 'think_'); $this->assertEquals(\think\Session::get('', 'think_')['sessionnamegetarrperall'], $_SESSION['think_']['sessionnamegetarrperall']); \think\Session::set('sessionnamegetper', 'sessionvalue', 'think_'); $this->assertEquals(\think\Session::get('sessionnamegetper', 'think_'), $_SESSION['think_']['sessionnamegetper']); \think\Session::set('sessionnamegetarrper.subname', 'sessionvalue', 'think_'); $this->assertEquals(\think\Session::get('sessionnamegetarrper.subname', 'think_'), $_SESSION['think_']['sessionnamegetarrper']['subname']); }
public function testPull() { Session::prefix(null); Session::set('sessionnamedel', 'sessionvalue'); $this->assertEquals('sessionvalue', Session::pull('sessionnameget')); $this->assertNull(Session::get('sessionnameget')); }
function session($name, $value = '', $prefix = null) { if (is_array($name)) { // 初始化 \think\Session::init($name); } elseif (is_null($name)) { // 清除 \think\Session::clear($value); } elseif ('' === $value) { // 判断或获取 return 0 === strpos($name, '?') ? \think\Session::has(substr($name, 1), $prefix) : \think\Session::get($name, $prefix); } elseif (is_null($value)) { // 删除session return \think\Session::delete($name, $prefix); } else { // 设置session return \think\Session::set($name, $value, $prefix); } }
/** * 检查 Session * * @return boolean true => 存在session,false => 不存在session */ protected function checkSession() { // 获得 $session = Session::get($this->sessionName); // 检查和设置 if ($session) { $this->setSession($session); return true; } else { return false; } }
/** * 获得用户保存的session值 * * @return null|int,返回null表示用户未登录,返回int表示的是用户的$user_id */ public function session() { return Session::get($this->auth_key); }