简体   繁体   English

会话在javascript重定向上丢失

[英]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: index.html的:

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

The problem is that in second() method session variable is empty. 问题在于在second()方法中,会话变量为空。 Why is that so? 为什么会这样?

You did not start the session. 您尚未启动会话。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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