delete() публичный статический Метод

删除session数据
public static delete ( string $name, string | null $prefix = null ) : void
$name string session名称
$prefix string | null 作用域(前缀)
Результат void
Пример #1
0
 /**
  * 跳转到上次记住的url
  */
 public function restore()
 {
     if (Session::has('redirect_url')) {
         $this->data = Session::get('redirect_url');
         Session::delete('redirect_url');
     }
 }
Пример #2
0
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);
    }
}
Пример #3
0
 /**
  * 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);
     }
 }
Пример #4
0
 /**
  * 验证表单令牌
  * @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;
 }
Пример #5
0
 /**
  * @covers think\Session::delete
  *
  * @todo Implement testDelete().
  */
 public function testDelete()
 {
     \think\Session::prefix(null);
     \think\Session::set('sessionnamedel', 'sessionvalue');
     \think\Session::delete('sessionnamedel');
     $this->assertEmpty($_SESSION['sessionnamedel']);
     \think\Session::set('sessionnamedelarr.subname', 'sessionvalue');
     \think\Session::delete('sessionnamedelarr.subname');
     $this->assertEmpty($_SESSION['sessionnamedelarr']['subname']);
     \think\Session::set('sessionnamedelper', 'sessionvalue', 'think_');
     \think\Session::delete('sessionnamedelper', 'think_');
     $this->assertEmpty($_SESSION['think_']['sessionnamedelper']);
     \think\Session::set('sessionnamedelperarr.subname', 'sessionvalue', 'think_');
     \think\Session::delete('sessionnamedelperarr.subname', 'think_');
     $this->assertEmpty($_SESSION['think_']['sessionnamedelperarr']['subname']);
 }
Пример #6
0
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);
    }
}