Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/session/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Session 刷新时的会话变量_Session_Laravel_Laravel 4_Controller - Fatal编程技术网

Session 刷新时的会话变量

Session 刷新时的会话变量,session,laravel,laravel-4,controller,Session,Laravel,Laravel 4,Controller,我的laravel控制器如下所示: public function postSessionTopic() { $article_id = Input::get('article_id', 0); $comment_id = Input::get('comment_id', 0); \Session::set('page_topic_id', $article_id); \Session::set('page_comment_id', $comment_id)

我的laravel控制器如下所示:

public function postSessionTopic() {

    $article_id = Input::get('article_id', 0);
    $comment_id = Input::get('comment_id', 0);

    \Session::set('page_topic_id', $article_id); 
    \Session::set('page_comment_id', $comment_id); 

    \\comment - I have tried \Session::put too, but that doesn't change anything


}
\Session::get('page_topic_id', 0)
当用户点击一篇文章时,我使用它。我在这个控制器中打印会话变量,一切看起来都很好。但在那个之后,我刷新我的页面,在那个里我从会话中读取值,有时它加载旧值或不加载任何内容。我不明白为什么,因为在控制器中我可以看到,正确的值被保存了

在我的页面中,我得到如下值:

public function postSessionTopic() {

    $article_id = Input::get('article_id', 0);
    $comment_id = Input::get('comment_id', 0);

    \Session::set('page_topic_id', $article_id); 
    \Session::set('page_comment_id', $comment_id); 

    \\comment - I have tried \Session::put too, but that doesn't change anything


}
\Session::get('page_topic_id', 0)

也许你做错了什么。您应该确保在这两种情况下,您使用的域名完全相同,有或没有www

在该控制器中,当您没有任何设置为会话变量0的输入时。如果在没有任何输入的情况下启动此方法,这也可能是一个问题

您可以尝试添加以下基本路线:

Route::get('/session', function() {

    $page_topic =  Session::get('page_topic_id', 1);

    $page_comment = Session::get('page_comment_id', 1);

    echo $page_topic.' '.$page_comment.'<br />';

    $article_id = $page_topic * 2;
    $comment_id = $page_comment * 3;

    Session::set('page_topic_id', $article_id);
    Session::set('page_comment_id', $comment_id);
});

等等。一切如期而至

答案是——一次两个ajax。不要这样做,如果你在会话中存储一些东西。

< P> Laravel中的会话不考虑永久性更改,除非生成响应,这是使用交响乐作为其基础的结果。因此,请确保应用程序->run正确结束,并在刷新之前返回响应。您的问题主要是由于代码中的某个die方法或PHP实例/工作者意外退出造成的。

这可能不是您的问题,但如果您将laravel会话存储在数据库中,则该值的大小会受到限制。Laravel会话迁移有一个名为payload的字段,该字段是文本类型。如果超出该字段的限制,则整个会话将被终止。当我在会话中动态添加json模型数据时,这种情况就发生了

    Schema::create('sessions', function (Blueprint $table) {
        $table->string('id')->unique();
        $table->text('payload');
        $table->integer('last_activity');
    });

检查您的会话cookie域,例如如果您的cookie保存到www.example.org,并且您访问example.loc,您将无法访问两个域中的同一会话始终是相同的。您是如何测试它的?例如,您需要手动刷新此urlhttp://localhost/project/session 你得到了价值。你得到了什么价值?