Home  >  Q&A  >  body text

thinkphp5.0 session 无法存储?

使用thinkphp5.0 Session类、

dump(Session::get('id'));

这里打印的结果是什么原因?

$id = input('get.id);

//第一次和id改变时进来
if(Session::get('id') != $id){
            echo '新id';
        }
Session::set('id',$id);

补充:

if($_SESSION['id] != $_GET['id])
{
   echo '新id';
}
$_SESSION['id] = $_GET['id];

我现在的问题就是:id没有改变,但是一直都会走到  echo '新id' 这里,什么原因?

在赋值之前打印 两个session 会有这个结果
代码:

某草草某草草2713 days ago608

reply all(3)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-05-16 13:02:00

    Please describe the problem clearly

    reply
    0
  • 为情所困

    为情所困2017-05-16 13:02:00

    The values ​​obtained by $_SESSION['id] and Session::get('id') are different. Because the Session class has a session prefix, what you get in $_SESSION['id] is not the value of Session::set('id',$id), so of course it will never wait.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:02:00

    It is not recommended to use the native $_SESSION in thinkphp

    reply
    0
  • Cancelreply