weixin_33749242 2012-12-19 09:04 采纳率: 0%
浏览 7

PHP知道用户是否在页面上

I am developing a Ticker support client in PHP with CodeIgniter, and I want to know if a user already open a ticket to hide this ticket from the list.

I know there is the solution of change a flag in database when the ticket is opened, then use :

 $(window).unload(function() {
    $.ajax({async:false ..... 
    /* change flag in database */
 });

But, what if the user's navigator is forcing to close ? Do I need a CRON task running to reset these flags ? Do you have some feedback for a complete solution ? Thanks.

  • 写回答

2条回答 默认 最新

  • weixin_33743880 2012-12-19 09:31
    关注

    Since PHP runs only once per page load, the only way to check continuously if a user is still on the desired page you need Javascript + AJAX. How?

    Every 1-5 minutes you update a specific field in the database using the timestamp of the last update (like you said) and in the PHP script you check that field in order to close or keep that ticket open.

    By the way notice that this solution requires Javascript enabled so either you force the user to enable it (by blocking it otherwise) or you define that after few minutes (15-1hr) of no page loading you close the ticket.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记