How to check / determine session age using PHP

北慕城南 提交于 2019-12-14 02:08:57

问题


I wonder if it's possible to check session age somehow with PHP. I have browsed trough stackoverflow and have not found anything. Thanks for all answers in advance.

In case anyone wonder why would I need to know something like this is, I want to show notification on top of the screen on all pages for all people are logged in less then 30 minutes.


回答1:


Why not just set $_SESSION['logged_in_at'] = time() when the user logs in, then check if( time() - $_SESSION['logged_in_at'] < 30*60)?




回答2:


$session_time = fileatime(session_save_path()."/sess_".session_id());
echo "Session Age (Seconds): ".(time()-$session_time);

Perhaps it isn't best practice but it'll do, in the absence of a native function like session_time().



来源:https://stackoverflow.com/questions/14093368/how-to-check-determine-session-age-using-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!