简体   繁体   中英

Session is lost on javascript redirect

I have two methods in my class:

class Foo {
   public first() {
      session_start();
      $_SESSION['a'] = 'a';
      $this->renderView('index.html');
   }
   public second() {
      var_dump($_SESSION); die();
   }
}

index.html:

<script type="text/javascript">
   window.location = "/foo/second";
</script>

The problem is that in second() method session variable is empty. Why is that so?

You did not start the session.

public function second() {
   session_start();
   var_dump($_SESSION); die();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM