duancan1900 2014-02-01 15:52
浏览 49

使用php和mysql自动注销

I am trying to make a chat room to my web page. and I want my users to know if the person they are trying to reach is afk/online/offline. i have looked around and found an answer on how to auto log out php sessions after a certain time. then you would have to add a timestamp when logged in an check if the time has passed the log out time if not you will have to update the time. so for my chat room i figured that I should add a time stamp when they logged on to the site in mysql. but then I would have to update this on every page. then the chat room would get all online users and check if the time stamp is less than 5 minutes ago. to avoid having the page use a long time loading the script i wanted to add this function in php at the bottom off the page where it update the time_stamp in the database every time the page is loaded.

so before I go on making this code I was wondering if this is a smart solution or if there is an easier way. I know i could make a javascript on the user and check if it should change the status but this would not work if the user has disabled javascript on my page.

so should I make my chat room user status like this or is there another better/smarter solution?

  • 写回答

2条回答 默认 最新

  • douyue6520 2014-02-01 16:37
    关注

    That solution is Ok. It it just one query to your Database. And it makes no differents if the query is on "the bottom", because the php script runs completly through your script and after that it sends the content to the user.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题