计算我的网站访问者访问我网站的确切时间。

编程入门 行业动态 更新时间:2024-10-27 02:26:26
本文介绍了计算我的网站访问者访问我网站的确切时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都可以知道如何计算访问者访问我的网站的持续时间 timeduration? 我的网站上没有会话,因为它不是用户特定的网站

can any one give idea how to calculate time duration for the visitor visit my website timeduration? there is no session on my website because it is not an user specific website

推荐答案

嗯......在实践中你不能准确,即使你强迫他们登录和退出。 没有什么可以告诉你的服务器这个用户已经离开了这个页面(更不用说这个用户已经停止了阅读本页并正在查看新闻) - 特别是如果你没有会话提供可靠的使用结束指示器。 那里是在javascript中检测页面关闭的方法 - 但它们并不总是有效 - 并且没有会话就没有办法将它们与用户开始阅读它的日期和时间联系起来。如果没有别的,同一个路由器上的所有用户都获得相同的IP地址,所以如果你有两个用户,你就不知道关闭页面的用户何时打开它。 你认为自己需要做什么?可能有更好的解决方案。 Um...in practice you can't be accurate, even if you force them to log in and out. There is nothing that tells your server "this user has moved away from this page" (much less "this user has stopped reading this page and is looking at the news instead") - particularly if you don't have a Session to provide a solid "end of use" indicator. There are ways to detect that a page is closed in javascript - but they don't always work - and without a session there is no way to tie even them to the date and time that the user started reading it. If nothing else, all users on the same router get the same IP address, so if you have two users, you don't know when the user closing the page opened it. What are you trying to do that you think you need this? There may be a better solution.

您可以做的最好是在每个页面上检查用户是否有您定义的cookie,如果没有创建具有当前date.\\time的cookie 。如果您读取此cookie的值并从当前日期时间中减去该值,那么这将让您知道他们在该请求时已经在您的网站上停留了多长时间。 您不知道用户何时关闭浏览器或导航离开您的网站,并且您无法根据此数据将内容推送到客户端,因此对您来说可能毫无用处。 Best you could do is that on every page check if the user has a cookie you define, and if not create one that has the current date\time. If you read the value of this cookie and subtract it from the current datetime then that'll let you know how long they've been on your site at the point of that request. You don't know when the user is closing their browser or navigating away from your site and you can't "push" content to the client based on this data either so it's probably useless to you.

更多推荐

计算我的网站访问者访问我网站的确切时间。

本文发布于:2023-11-27 05:42:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网站   访问者   确切   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!