简体   繁体   English

PHP:使用Date Diff等搜索过去15分钟内已登录的用户

[英]PHP: Searching for users that have logged in within the last 15 minutes using Date Diff, etc

This has been asked before, however I can not for the life of me find it on google or stackoverflow for a solution. 之前曾有人问过这个问题,但是我终生无法在Google或stackoverflow上找到解决方案。 I even entered this into my google search: php date("F j, Y, g:ia") date diff. 我什至在Google搜索中输入了此内容:php date(“ F j,Y,g​​:ia”)date diff。 So, I will ask it here. 所以,我会在这里问它。

I have a date set throughout my whole website that is set like this (done in PHP): 我在整个网站上设置了一个这样的日期(用PHP完成):

  date_default_timezone_set('US/Eastern');  
$CurLogIn = date("F j, Y, g:i a");

That date then gets SQL Updated into each users lastloginfield to basically check when it was the last time they accessed my page. 然后,该日期将SQL Update更新到每个用户的lastloginfield中,以基本上检查这是他们最后一次访问我的页面的时间。 I wanted to create a page which displays users that have been on a page on my site within the last 15 minutes. 我想创建一个页面,以显示过去15分钟内访问过我网站页面的用户。 However, I cant find a Date Diff Solution for how I set up the time/date above. 但是,我找不到上面设置时间/日期的日期差解决方案。

Does anyone have a solution for how I can check for all users that have accessed a page within the last 15 minutes using that time format above? 是否有人可以使用上面的时间格式来检查过去15分钟内访问过该页面的所有用户的解决方案? Thanks. 谢谢。

填写您的字段和表格名称

SELECT * from table where NOW() - INTERVAL 15 MINUTE <lastloginfield

You can do this directly from SQL 您可以直接从SQL执行此操作

SELECT * 
FROM user
WHERE (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(last_login) < (60 * 15))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM