PHP会话不会刷新使用AJAX [英] PhP Session does not refresh using AJAX

查看:146
本文介绍了PHP会话不会刷新使用AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经寻找高和低一个答案。我有一个网站,播放很长的视频文件。我不希望用户在观看视频超时,所以我希望把一个AJAX调用上刷新会话计时器。有人告诉我很多,这样做的刷新页面上的会议什么就足够了,但没有什么工作。我有PHP会话过期设置为30分钟。我宁愿不增加这个了。

I have searched high and low for an answer to this. I have a site that plays long video files. I do not wish the user to timeout while watching a video, so I wanted to put a AJAX call on a timer that refreshes the session. I was told by many that doing anything with the session on the refresh page would be enough, but nothing is working. I have the php session expire set to 30 minutes. I would rather not increase this anymore.

下面是我的jQuery / AJAX调用

Here is my jquery / AJAX call

//var time = 20000; // for live
var time = 10000; // for testing

// loop to handle refresh session
setInterval(function() {

    // ajax call to get image
    $.ajax({
        url: 'refreshSession.php',
        cache: false,
        async: false,
        type: "POST",
        data: {},
        success: function(){},
        error: function(request, status, error){
            alert('Login Session Error: ' + request.responseText + '  STATUS: ' + status + '  ERROR: '+error);
        }
    }); 
}, time);

AJAX调用是伟大的工作和正常循环。这是我需要保持会话活着refreshSession.php文件。

The AJAX call is working great and loops correctly. Here is the refreshSession.php file which i need to keep the session alive.

<?php
include_once("configure.php");

// store session data
if (isset($_SESSION['userData']['userID']))
    $_SESSION['userData']['userID'] = $_SESSION['userData']['userID']; // or if you have any algo.
?>

请注意,该文件的configure.php不调用在session_start();我写的会话ID和其他信息和正确的信息是被写入文件。所以我知道这个PHP文件中读取会话变量。

Note, that the configure.php file does call the session_start(); I was writing to a file the session id and other info and the correct information was being written. So I know this php file is reading the session variables.

然而,30分钟后,我得到注销,会话被重置。是否有什么我失踪?

However, after 30 minutes, I get logged out and the session is reset. Is there something I'm missing?

推荐答案

本:

<?php
 include_once("configure.php");

应该是:

<?php
session_start(); //This line is missing
include_once("configure.php");

这篇关于PHP会话不会刷新使用AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆