Auto-Update "Users Online" [RevCMS/Phoenix/BcStorm]
This is how to make your "Users Online" On the homepage change automatically, without having to reload the homepage. I did this with RevCMS, I'm not sure about UberCMS, Also, I have only tested this with Phoenix, So I don't know about other emulators. Anyways, lets get started.
EDIT: This works with BcStorm and RevCMS Also, Thanks to Prizm for testing!
First, make a file in your root directory, then name it "online.php" or something, it doesn't matter. (Will need to be changed later if its not online.php)
Then, paste this and save it (Make sure you edit 'DBPASS' and 'DBNAME'
PHP Code:
<?php$con = mysql_connect("localhost","root","DBPASS");
Mysql_Select_db("DBNAME", $con);
$q = mysql_query("SELECT * FROM server_status");
while($row = mysql_fetch_assoc($q)){
echo $row['users_online'];
}
?>
Then go to every page that has "online users" and make/add this:
PHP Code:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script><script type="text/javascript">
function getUsers() { $.get('online.php', function(data) { $('.reload_users').html(data); }); setTimeout(getUsers, 1); } $(document).ready(function(){ getUsers(); });
</script>
Then where the "Online users" part is, change it to this:
PHP Code:
<span class="online_users"> <span class="reload_users"></span> User(s) Online!</span>
Credits:
50% To @Welfordian on twitter. (For making it all)
30% For me releasing and testing for Phoenix and RevCMS
20% To Prizm for testing on BcStorm and RevCMS
Re: Auto-Update "Users Online" [Phoenix]
Re: Auto-Update "Users Online" [Phoenix]
Haha, I have looked for this :p
Thanks Hyp, I'm very apreciated! :):
Re: Auto-Update "Users Online" [Phoenix]
Cool, I'll test it. Might slow down the site, though.
Re: Auto-Update "Users Online" [Phoenix]
<?php
$con = mysql_connect("localhost","root","DBPASS");
Mysql_Select_db("DBNAME", $con);
$q = mysql_query("SELECT * FROM server_status");
while($row = mysql_fetch_assoc($q)){
echo $row['users_online'];
}
?>
lol?
<?php
$result = mysql_result(mysql_query('SELECT `users_online` FROM `server_status` LIMIT 1'), 0);
echo $result;
?>
Re: Auto-Update "Users Online" [Phoenix]
Quote:
Originally Posted by
ImJoeYz
not bad.
Thanks :P
Quote:
Originally Posted by
Prizm
Haha, I have looked for this :p
Thanks Hyp, I'm very apreciated! :):
Your welcome, good to know I'm helping :D
Quote:
Originally Posted by
Riley H
Cool, I'll test it. Might slow down the site, though.
I tested it on my localhost, it didn't slow it down:/ it takes a second to catch the users going online or offline though.
Quote:
Originally Posted by
Monsma
<?php
$con = mysql_connect("localhost","root","DBPASS");
Mysql_Select_db("DBNAME", $con);
$q = mysql_query("SELECT * FROM server_status");
while($row = mysql_fetch_assoc($q)){
echo $row['users_online'];
}
?>
lol?
<?php
$result = mysql_result(mysql_query('SELECT `users_online` FROM `server_status` LIMIT 1'), 0);
echo $result;
?>
Looks like it would work, although mine looks easier? .-.
Re: Auto-Update "Users Online" [Phoenix]
This is for the online header top, like on xen, correct? :O
Re: Auto-Update "Users Online" [Phoenix]
No need for Jquery here....
Only thing to change is the class must be also the id...
Also Calling it every millisecond is a bit heavy if you've got i.e. 200 users online:
200*60 = 12000
=> 12000 Requests/second
Thats no good neither for the Webserver nor the mysql server...
So this script gets the data only every second.
Perhaps you'd consider taking it to a minute...
PHP Code:
function getUsers() {
var http;
if (window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
http.onreadystatechange=function()
{
if (http.readyState==4 && http.status==200)
{
document.getElementById("reload_users").innerHTML= http.responseText;
setTimeout(getUsers, 1000);
}
}
http.open("GET", "online.php?noCache=" + Math.random(), true);
http.send();
}
window.onload = getUsers();
Onlineuser part must be like this:
PHP Code:
<span class="online_users"> <span id="reload_users" class="reload_users"></span> User(s) Online!</span>
Re: Auto-Update "Users Online" [Phoenix]
It works on BcStorm, just tested.
Re: Auto-Update "Users Online" [Phoenix]
Quote:
Originally Posted by
JTS
This is for the online header top, like on xen, correct? :O
I have no idea what you are talking about, this makes the number of the "users online" part on the homepage update automatically.. where you don't have to reload the site to see the correct amount.
Quote:
Originally Posted by
Prizm
It works on BcStorm, just tested.
Thanks man! Will add to the thread! Also, Credits to you for testing with BcStorm, Thanks again :)
Quote:
Originally Posted by
flx5
PHP Code:
<span class="online_users"> <span id="reload_users" class="reload_users"></span> User(s) Online!</span>
You sir are incorrect, It doesn't have to be this, it works fine the way mine is. + your way looks confusing, mine has an easy setup..
Re: Auto-Update "Users Online" [RevCMS/Phoenix/BcStorm]
Your jQuery code is wrong? You're using the setTimeout function that's activate the functions after x seconds. After that it isn't doing anything anymore. You need to use the setInterval function.
I wouldn't recommend this. This slows down the page. If you open the client with a page where a user online refresher is coded, the client laggs as shit.
I would recommend Javascript. Not jQuery. Javascript checks 'backstage' all the information you need. Like, if user online is higher than the current user online it's showing up. Same story if user online is lower.
My point: don't use this if you don't want a slow site with a laggy client.
Re: Auto-Update "Users Online" [RevCMS/Phoenix/BcStorm]
Better way to get users online for BCStorm
Code:
$online = mysql_num_rows(mysql_query("SELECT * FROM users_active"));
Re: Auto-Update "Users Online" [RevCMS/Phoenix/BcStorm]
Quote:
Originally Posted by
Divide
Better way to get users online for BCStorm
Code:
$online = mysql_num_rows(mysql_query("SELECT * FROM users_active"));
Even better way would be
PHP Code:
$online = mysql_result(mysql_query("SELECT COUNT(*) FROM users_active"), 0);
Re: Auto-Update "Users Online" [RevCMS/Phoenix/BcStorm]
Quote:
Originally Posted by
PremiumEye
Your jQuery code is wrong? You're using the setTimeout function that's activate the functions after x seconds. After that it isn't doing anything anymore. You need to use the setInterval function.
I wouldn't recommend this. This slows down the page. If you open the client with a page where a user online refresher is coded, the client laggs as shit.
I would recommend Javascript. Not jQuery. Javascript checks 'backstage' all the information you need. Like, if user online is higher than the current user online it's showing up. Same story if user online is lower.
My point: don't use this if you don't want a slow site with a laggy client.
I have 1gb ram vps and it doesn't lagg one bit?:L
-------------------------------------------------------------------------------
Anyways, Thanks to all contributing to this, Me and Welfordian were just releasing a little something;), expect more releases from me! :)
Re: Auto-Update "Users Online" [RevCMS/Phoenix/BcStorm]
Quote:
Originally Posted by
Hyp
I have 1gb ram vps and it doesn't lagg one bit?:L
-------------------------------------------------------------------------------
Anyways, Thanks to all contributing to this, Me and Welfordian were just releasing a little something;), expect more releases from me! :)
That doesn't matter? Jquery is a website script plugin. It haves nothing to do with ram. And it doesn't lagg because this script is refreshing one time.
Re: Auto-Update "Users Online" [RevCMS/Phoenix/BcStorm]
Quote:
Originally Posted by
PremiumEye
That doesn't matter? Jquery is a website script plugin. It haves nothing to do with ram. And it doesn't lagg because this script is refreshing one time.
Oh noes.. Some nub with a crap internet..