PHP用户在线脚本 [英] PHP Users Online Script

查看:55
本文介绍了PHP用户在线脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好TSDN的好人!我在这里有一个需要帮助的小脚本...我想要一个脚本告诉我有多少人一次查看一个页面或一个目录,EG:index.php上有多少用户或者有多少用户在/ forums目录。我有一个点击计数器脚本,我将在这里发布给任何想要的人,我认为它很好用,我只需要一个当用户离开目录时失效的计数器。我还想要一个计数器来计算有多少人在他们的浏览器中有会话字符串[''userid''],这是m网站告诉你是否登录的方式。有人可以帮我这个吗?


计数器代码:

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号

解决方案

嗯,我认为不可能查看来自其他用户的会话数据,因此跟踪以这种方式登录的用户数量将无法正常工作。


当用户离开页面时,您永远无法捕获。那是;用户可以关闭他/她的浏览器/标签,你永远不会知道它。

所以跟踪用户正在查看的内容的唯一方法是让页面当前打开写入它已被打开somwhere,然后在预设的时间段过去后使该日志条目无效。


这对使用数据库来说相当简单,比如MySQL。

您只需创建一个存储每个用户当前位置的表,然后选择在设定的时间内创建/更新的那些记录。


这样您就可以获得非常准确的估计有多少用户登录以及每个用户最多的用户。


如果您不想使用数据库,则必须创建自己的系统来存储数据需要,这在我的经验中比使用该死的数据库要麻烦得多,即使你没有或经验丰富。


然后我将再次使用SQL ...我看着一些扁平的文件pts,如果他们被编码,他们真的很大!现在,如果我使用SQL,我是否可以在不重新加载页面的情况下更新信息? EG:我可以坐下来观看数字变化吗?



然后我将再次使用SQL ...我看了一些平面文件脚本,如果它们被编码,它们真的很大!现在,如果我使用SQL,我是否可以在不重新加载页面的情况下更新信息? EG:我可以坐下来观看数字的变化吗?



好​​吧,您的浏览器收到的任何代码都只是来自服务器的静态输出,所以简短的答案是否定的。

然而,如果你想要长答案,那么它将是''AJAX''。哪个是基本的Javascript,您可以使用它定期向服务器发送请求,请求更新,然后您可以使用它来更新静态输出。 (顺便说一句,这就是静态部分引用的原因)


所以,是的,这是可能的,但在我的诚实意见中,只需按下刷新按钮就会简单得多时不时。


PS

这与SQL无关,无论用什么方法跟踪用户都是一样的。


Hello good people of TSDN! I have a little script here that need help with... I want a script that tells me how many people are viewing a page or a directory at a time, EG: How many users are on index.php or how many users are in the /forums directory. I have a hit counter script that i will post here for anybody wanting one, and i think it works great, i just need a counter that goes down when a user leaves directory. I would also like a counter that counts how many people have the session string [''userid''] in their browser, which is m sites way of telling if your logged in or not. Can somebody please help me on this?

The counter code:

Expand|Select|Wrap|Line Numbers

解决方案

Hmm, I do not think it is possible to view session data from other users, so tracking how many users are logged in that way won''t work.

You can never catch when a user leaves a page. That is; a user can close his/her browser/tab and you will never know about it.
So the only way to track what a user is viewing is to have the page currenty open write that it has been opened somwhere, and then invalidate that log entry when a preset period of time has passed.

This would be fairly simple using a database, like say MySQL.
You would simply create a table that stored the current location of each user, and then select those records created/updated whitin a set ammount of time.

This way you can get a pretty accurate estimate of how many users are logged in and what each user is up to.

If you do not want to use a database you will have to create your own system of storing the data you need, which in my experience is much more trouble than just using the damn database, even if you have no or litte experience with it.


Then i shall use SQL once more... i looked at some flat file scripts, and if they werend encoded they were really huge! Now, if iuse SQL, can i get it to update the information WITHOUT reloading the page? EG: I can just sit back and watch the numbers change?


Then i shall use SQL once more... i looked at some flat file scripts, and if they werend encoded they were really huge! Now, if iuse SQL, can i get it to update the information WITHOUT reloading the page? EG: I can just sit back and watch the numbers change?

Well, any code received by your browser is just ''static'' output from the server, so the short answer is no.

HOWEVER, if you want the long answer, then it would be ''AJAX''. Which is basicly Javascript that you can use to periodicly send a request to the server, asking for updates which you can then use to update the ''static'' output. (which btw is the reason for the quotes arround the static part)

So, yes it is possible, but in my honest opinion, It would be much simpler to just press the refresh button every now and then.

P.S.
This really has nothing to do with SQL, it would be the same whatever method you would use to track your users.


这篇关于PHP用户在线脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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