如何防止 Zend Framework 清除现有会话? [英] How can I keep Zend Framework from wiping out an existing Session?

查看:39
本文介绍了如何防止 Zend Framework 清除现有会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我接到了一项并不有趣的任务,即尝试将 Zend 框架实例与过时的遗留代码结合起来,而无需对遗留代码进行太多修改.其中一部分是一个多页表单,它接收大量数据,对其进行验证、处理,然后通过电子邮件将其发送给网站所有者.我的工作是将这些数据导入 ZF,然后我可以将其自动处理到数据库中.我不能使用 POST.我宁愿避免使用自动提交表单,因为我认为我不应该使用 Javascript.Get 会非常笨拙.

I've been given the not fun task of trying to marry a Zend framework instance to antique legacy code with out much modifying the legacy code. Part of this is a multipage form that takes in a heap of data, verifies it, processes it and then sends it to the websites owner in an e-mail. My job is to get that data into ZF where I can auto process it into a database. I cannot use POST. I'd rather like to avoid using an autosubmitting form as I don't think I'm supposed to be using Javascript. Get would be painfully unwieldy.

我希望使用会话从现有的表单处理器中获取数据并进入 ZF.数据已经在表单处理器中的会话中.起初,我认为重定向到我的 ZF 实例(它存在于主网站的子目录中)是一件简单的事情.这是同一个域,应该是同一个会话,对吧?

My hope was to get the data out of the existing form processor and into ZF using the Session. The data is already in the Session in the form processor. At first, I figured it'd be a simple matter of redirecting into my ZF instance (which exists inside a subdirectory of the main website). It's the same domain, ought to be the same session, right?

好吧,ZF 处理其会话的方式导致旧的会话数据被完全彻底清除.刚刚没了.

Well, something about the way ZF handles its sessions causes the old session data to be completely and utterly wiped out. Its just gone.

那么,ZF 是否以清除现有会话的方式处理其会话,还是侥幸?如果这不是侥幸,我该如何绕过它?如果是,可能是什么原因造成的/我该如何解决?

So does ZF handle its Session in such a way that it wipes out the existing session or is this a fluke? If this isn't a fluke, how can I bypass it? And if it is, what might be causing it/how can I fix it?

编辑

我将 Zend_Session_SaveHandler_DbTable 用于数据库支持的会话.这是在 application.ini 中初始化的.初始化代码如下:

I am using Zend_Session_SaveHandler_DbTable for database backed sessions. This is initialized in the application.ini. Here is the initializing code:

resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "Sessions"
resources.session.saveHandler.options.primary = "sessionID"
resources.session.saveHandler.options.modifiedColumn = "lastModifiedTime"
resources.session.saveHandler.options.dataColumn = "data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"

在我使用会话的地方,我尝试调用 session_start(),但这会产生错误.可能是因为保存处理程序代码已经初始化了会话,或者稍后初始化.如果我尝试直接访问 $_SESSION 变量,则会出现一个错误,指示我试图访问未设置的变量.如果我先创建一个 Zend_Session_Namespace 然后尝试访问 $_SESSION,我将面临一个空会话.

Where I am using the session, I have tried calling session_start(), but that creates an error. Probably because the save handler code has already initialized the session, or does so later. If I try to access the $_SESSION variable directly, I can an error indicating I attempted to access an unset variable. If I create a Zend_Session_Namespace first and then attempt to access $_SESSION, I am faced with an empty session.

推荐答案

因为您已将 ZF 设置为将会话保存到数据库而不是文件系统,所以具有不使用相同 ZF 引导程序代码的脚本 尝试调用会话将失败.(即便如此,他们也可能使用两个完全不同的会话 cookie 名称...)

Because you have ZF set up to save sessions to the database instead of the filesystem, having scripts that don't use the same ZF bootstrap code try to invoke the session will fail. (Even then, they could also be using two entirely different session cookie names...)

因为您暗示 ZF 位是,那么解决方案很简单:暂时停止使用 ZF 的会话位.这意味着没有数据库表保存,没有命名空间处理程序,什么都没有.使用原始 $_SESSION 超全局变量,并使用与旧代码相同的会话设置.这是确保两个应用程序都访问相同会话数据而不修改遗留代码的唯一方法.

Because you've implied that the ZF bits are new, then the solution is simple: Stop using the session bits of ZF for now. This means no database table saving, no namespace handler, nothing. Work with the raw $_SESSION superglobal, and use the same session settings as the legacy code. This is the only way to make sure that both applications get access to the same session data without modifying the legacy code.

这篇关于如何防止 Zend Framework 清除现有会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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