Zend_Session:确定Session是最初启动还是刚刚更新
我的 Zend_Session 有问题。我需要知道该用户的会话是第一次启动还是刚刚在当前请求中更新。
我需要知道这一点以进行统计。如果会话已初始化(意味着用户第一次访问我的应用程序),我想将请求的引用存储在某个数据库表中。当然,我只想针对本次会话中的第一个请求执行此操作。
该手册讨论了 Zend_Session::isStarted()
和 Zend_Session::sessionExists()
方法。但似乎这两种方法都只适用于当前请求(这意味着如果我在应用程序中的某处使用 Zend_Session::start()
,它会返回 true )。
我的方法如下: 我尝试重写 Zend_Session::start() 来将统计数据插入到我的数据库表中。
// Somewhere in my bootstrap:
My_Session::start();
// This is my class (eased up)
class My_Session extends Zend_Session
{
public static function start($options)
{
parent::start($options);
if(/* Here I need the condition to test, if it was the initial session-starting... */)
{
$table = new Zend_Db_Table(array('name' => 'referer'));
$row = $table->createRow();
$row->url = $_SERVER['HTTP_REFERRER'];
$row->ip = $_SERVER['REMOTE_ADDR'];
// ... some columns ...
$row->save();
}
}
}
有人有什么想法吗?
I've got a problem with Zend_Session. I need to know, if the Session for this user was initially started the first time or if it was just updated in the current request.
I need to know that for statistics. If the session was initialized (meaning the user visits my app for the first time) I want to store the referer of the request in some db-table. This of course I only want to do for the first request within this session.
The manual talks about the methods Zend_Session::isStarted()
and Zend_Session::sessionExists()
. But it seems that both methods only work for within the current request (meaning it returns true if I use Zend_Session::start()
somewhere in my app).
My approach was the following:
I tried to override Zend_Session::start()
to insert the statistic-data into my db-table.
// Somewhere in my bootstrap:
My_Session::start();
// This is my class (eased up)
class My_Session extends Zend_Session
{
public static function start($options)
{
parent::start($options);
if(/* Here I need the condition to test, if it was the initial session-starting... */)
{
$table = new Zend_Db_Table(array('name' => 'referer'));
$row = $table->createRow();
$row->url = $_SERVER['HTTP_REFERRER'];
$row->ip = $_SERVER['REMOTE_ADDR'];
// ... some columns ...
$row->save();
}
}
}
Anybody has any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是问题:
Not a problem: