总之,以检测用户是否使用PHP关闭浏览器? [英] Anyway to detect whether user close the browser using php?

查看:166
本文介绍了总之,以检测用户是否使用PHP关闭浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  检测在PHP浏览器退出

我在我的服务器用户的一些相关的文件,我希望他们当用户关闭浏览器或离开我的网页被删除。是否可以?有没有办法做到这一点?

I have some user related files in my server and I want them to be deleted when user closes the browser or leaves my page. Is it possible? Is there any way to do it?

推荐答案

不只是用PHP。

PHP运行服务器端,并且目前已经完成的时间处理你的页面的用户将有机会来关闭浏览器。你可以在技术上检测是否PHP仍在处理页面和用户关闭它,用特定的配置。然而,这是不理想的。请参见 connection_aborted()

PHP runs server-side, and is far done processing your page by the time the user will have a chance to close their browser. You could technically detect if PHP was still processing the page and the user closes it, with a specific configuration. However, it is not ideal. See connection_aborted().

您需要做的是建立使用JavaScript长轮询连接,并监视它的服务器端是什么。然后,您将获得在关闭该窗口的想法。这一方面可以作出你的PHP脚本,让PHP检查 connection_aborted()。请注意,您需要设置 ignore_user_abort () 这个工作,或者配置相应的php.ini。

What you need to do is set up a long-polling connection with JavaScript, and monitor it server-side. You will then get an idea for when that window is closed. That connection could be made to your PHP script, allowing PHP to check connection_aborted(). Note that you will need to set up ignore_user_abort() for this to work, or configure PHP.ini accordingly.

这篇关于总之,以检测用户是否使用PHP关闭浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆