search

Home  >  Q&A  >  body text

thinkphp5.0 session cannot be stored?

Use thinkphp5.0 Session class,

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

What is the reason for the results printed here?

$id = input('get.id);

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

Supplement:

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

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

Print two sessions before assignment will have this result
Code:

某草草某草草2790 days ago646

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