让客人和会员网站,看看谁在线/登录使用AJAX,PHP / PDO,CSS,HTML [英] allowing guests and members of site to see who is online/logged in using ajax, php/pdo, css, html

查看:73
本文介绍了让客人和会员网站,看看谁在线/登录使用AJAX,PHP / PDO,CSS,HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找遍了所有过网,并不能找到一个解决的办法。我在AJAX没有经验,但知道这将需要执行这一功能,因为我相信这将是比只使用纯JavaScript更好。

I have searched all over the net, and can't find a solution to this. I have no experience in AJAX but know it will be needed to perform this function as I believe it would be better than just using pure javascript.

我有谁注册在我的网站成员列表,列表是一个单独的页面 - >该列表的每个成员上,有一个绿色圆点(如成员是在网上表示),如果用户离线(灰点显示)。我有一个占位符,目前只使用CSS和HTML。该<网上/> <离线/> 是在&LT ; H2> 标签就像一个<跨度> 标记。有没有一种方法来自动更新这表明谁是真正的登录/退出实时和不使用NodeJS和/或SocketIO?

I have a list of members who registered on my site, list is on a separate page --> on that list for each member, there is either a green dot (signifies if member is online) and if the user is offline (grey dot shows). I have that as a placeholder at the moment using only css and html. The <online /> and <offline /> are within the <h2> tag almost like a <span> tag. Is there a way to auto-update this to show who is actually logged in/out in real-time and without using NodeJS and/or SocketIO?

的HTML看起来是这样的:

The html looks like this:

<h2>Billy <online title="Online" /></h2> 

&LT;网上标题=在线/&GT; 随后将显示他们的名字旁边的绿点,如果在线(登录)。如果他们没有登录,HTML应该是这样的:

Where the <online title="Online" /> will then display the green dot next to their name if online (logged in). If they are not logged in, the html should look like this:

<h2>Billy <offline title="Offline" /></h2>

&LT;离线标题=离线/&GT; 随后将显示他们的名字旁边的灰点,如果离线(注销)

Where the <offline title="Offline" /> will then display the grey dot next to their name if offline (logged out).

就像我也提到过,我在AJAX没有经验,但我pretty的确定它的东西,我需要进行自动更新/刷新的时间只为这部分单独 - 所以不是整个页面.. 。而我有点熟悉PHP,所以我会使用 SESSION_ [ID] 看/收集有关谁是登录,谁的信息库查询是没有的。

Like I also mentioned, I have no experience in AJAX but am pretty sure it's something I'd need to perform an auto-update/refresh time just for this section alone - so NOT for the entire page...And I am a little familiar with PHP, so I would base a query using SESSION_[ID] to see/gather information on who is logged in and who isn't.

如果有人可以帮助,我会非常AP preciate吧,我已经searchin几天就如何做到这一点,并不能找到什么...

If anyone could help, I'd greatly appreciate it, I've been searchin' for days on how to accomplish this and cannot find anything...

什么,我现在有演示: http://jsfiddle.net/tZpk6/

Demo of what I currently have: http://jsfiddle.net/tZpk6/

推荐答案

虽然我不是所有的JS看中,这基本是简单地更新了最新的时间被记录或执行的人你的数据库中的表动作 - 当你感到显示有关用户的信息,您只需查询该表 - 任何人说,过去的五到十分钟谁了一些活动被认为是在线 - 和其他人......嗯不是

While I am not all JS fancy, the basics of this is to simply update a table in your database with the latest time that someone was logged in or performed an action - then when you are displaying the information about users, you simply query that table - anyone in say the last five or ten minutes who had some kind of activity is considered "Online" - and others... well aren't.

您的脚本不能真正使用会话ID - 因为它们是独一无二的,只看到是谁在运行code用户。我的意思是,虽然你可能在你的网站上的12名用户,所有的人都在使用一个会话变量,他们不能与人交往。每个用户(和我的意思是code运行)只能访问自己的会话变量。如果你希望他们能够看到对方,但必须通过一个中间设备完成,如数据库或文件 - 或者说是不断运行的实际应用 - 用Java或C#之类,这是总是从PHP code运行和传递数据。

Your script can't really use session IDs - as they are unique and only visible to the user who is running the code. By that I mean, that although you might have a dozen users on your site, all of whom are using a session variable, they cannot interact with one another. Each user (and by that I mean the code running) can only access their own session variables. If you want them to be able to see each other, it has to be done via an intermediary device such as a database, or a file - or an actual application that is constantly running - written in Java or C# or the like, which is ALWAYS running and being passed data from the PHP code.

因此​​,基本上,虽然你可以使用AJAX来检查不断的更新,在后台的数据是pretty的通过一个简单的表要始终做到这一点,你可以实现无论是在页面重载或变得有点票友和检查它通过脚本定期运行在你的页面。

So basically, although you can apply AJAX to check constantly for the updates, the data in the background is pretty much always done via a simple table that you can implement either on page reload or get a bit fancier and check it on a regular basis via scripts running inside your page.

这篇关于让客人和会员网站,看看谁在线/登录使用AJAX,PHP / PDO,CSS,HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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