我们可以在Coldfusion中更新会话吗?

时间:2011-04-25 19:41:00

标签: coldfusion coldfusion-8

我在会话中存储了5-6个变量值。有关如何在会话结构即将到期时续订会话结构的任何建议?我正在使用Coldfusion 8。 谢谢!

4 个答案:

答案 0 :(得分:6)

使用AJAX ping服务器以保持会话活动

或者只是简单地延长会话超时timeSpand。

答案 1 :(得分:2)

从该会话调用CFM页面将导致会话被扩展。我所看到的是一个JS计时器将在会话到期前不久运行和结束。当计时器运行时,它会触发一个加载非CFM页面(基本HTML)的弹出窗口,该页面会显示有关会议即将结束的消息,并询问用户是否要继续使用它。

答案 2 :(得分:1)

以下是关于自动ping服务器的Ajax的概念(如Henry's answer中所述。)

//This function will keep the session alive as long as the page is still open.
//Whenever the page nears expiration, it automatically extends it. 
function autoExtendSession(days,hours,mins,secs){
    var milliseconds = (days*86400000)+(hours*3600000)+(mins*60000)+(secs*1000);
    setTimeout(
    function(){
        $.post("server/heartbeat.cfm");
        console.log("Heartbeat sent to the server.");

        //Start another timer.
        autoExtendSession(days,hours,mins,secs)

    //Once we are 98% of the way to the timeout, the heartbeat is sent.
    //This way the timeout should never actually be reached.
    }, milliseconds-(milliseconds*0.02));
};

hearbeat.cfm页面实际上不需要包含任何内容,服务器会在$ .post点击它时更新会话,无论它是否有内容。

答案 3 :(得分:0)

完全执行您要求的方法是在onSessionEnd触发时将会话数据推送到数据库中,并在下一个onSessionStart恢复它。要查找要读取的数据条目,您可以将cookie放入用户的浏览器中,并使用唯一标识符(例如,该条目的盐渍+加密ID),这种“记住我”的东西。