开发者

PHP session starter detect for visitor counting

开发者 https://www.devze.com 2022-12-19 17:40 出处:网络
Is there a way to find out on session being started. Like for instance the session start eve开发者_运维知识库nt in the global.ascx file of .net. The requirement is to find the no. of visits the user h

Is there a way to find out on session being started. Like for instance the session start eve开发者_运维知识库nt in the global.ascx file of .net. The requirement is to find the no. of visits the user has done on the site.

Instead of checking each time during posts or gets to the server. Is there something in php to find out if the session is a new one. Zen framework is also used for the app.


Zend_Session::isStarted() and Zend_Session::sessionExists() will tell you if the session is already started. To find out when it was started for the first time, you could store the timestamp it was created, by adding it to the session on the very first startup. Just check if a key started_at already exists in the Session and if not add it and/or notify some other class about it to do something.


You can actually mimic what is done by global.ascx file through php and also there are a number of scripts available online for tracking online users you need to google about that.


you can use memcache for that purpose, or simply hack with a file(mentioned on Safraz answer) on the disc, or use a table on your database for that purpose.

Memcache appears to me the best solution since it is easy to setup and they already provide counter with increment/decrement. The only drawback of this solution your won't be able to reset the counter easily.

0

精彩评论

暂无评论...
验证码 换一张
取 消