Default Skins: Default | Black | Red | Green | Brown | Lavender

Techno Skins: Black | Blue | Brown | Green | Orange | Pink | Purlple | Red | Turquoise

Light Skins: Blue | Brown | Golden | Lilac | Navy | Olive | Red | Rose | Silver | Turqouise | Violet

Other Skins: Helios Blue | Helios Green | Helios Purple | Helios Red | Blue Mousse | Camo | Chronicles | Red Fire | Rusted | Grey and Blue | Grey and Green | igOH Mimic | Vista Mimic
Supernovadelta
March 20, 2010, 12:26:23 pm
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
  Home   Forum   Help Search Arcade Gallery Links Staff List Login Register  

How to make your website tell you how much people are logged in to the server.


Pages: [1]
  Print  
Author Topic: How to make your website tell you how much people are logged in to the server.  (Read 40 times)
Got Java?
First Time Poster
*

Rep: +1/-0
Posts: 1


View Profile
« on: June 08, 2008, 09:41:09 pm »

This tutorial is to make your website for your server tell you how much players are online at the moment.


You start off with remembering yourself of your SQL server Host, Username(probably 'root') and Password.
Also you should know what field in your database tells if a player is logged on.
On a Dodian/Devias/Devolution (SQL) server it would be field 'online' in table 'uber3_players'.
If you have any other source with SQL, look for something like loggedon or online or anything like that.

now Take a look at this code:
Code:
<?php
$connection 
mysql_connect[B]('HOST','USER','PASSWORD')[/B];
mysql_select_db('[B]DATABASE[/B]'$connection);
$query mysql_query('SELECT * FROM [B]uber3_players[/B] WHERE [B]online[/B] > 0');
$rows mysql_num_rows($query);
if($rows == 0){
$playersOnline "0 players online";
} elseif($rows == 1){
$playersOnline "1 player online";
} elseif($rows 1){
$playersOnline $rows." players online";
} else {
$playersOnline "Error occured";
}
?>
Create a new PHP file named 'online.php' with the code above in it.
change the following values:

HOST = your server host.
USER = SQL server username (probably root)
PASS = SQL server password
DATABASE = The database you used for your Server.


Now as you can see i used a Dodian server for example.
I bolded out the uber3_players and online because that part shows what to change if you have another database.
in my case what it does is:
SELECT * (select everything)
FROM uber3_players (from table uber3_players in the database we specified before)
WHERE online > 0 (where online is bigger then 0. My server sets that value to 1 if a player is logged in 1 minute, but this script also works if your server doesnt set the minutes, but just sets online (1) of offline (0) .)
So now it has selected all players wich have their online field set to 1.
The php script counts the rows, and knows how many players are logged in on your server.
It attaches it to a string named "$playersOnline".
Next thing is including and echoing the string out.


Now to make your website show how many players are logged in you need a little piece of PHP script:

Code:
<?php
include ("online.php");
echo 
"$playersOnline"?>

*Please notice*
If the PHP file 'online.php' isn't in the same directory as the script in which you are going to include this script, you need to change the URL to your location of 'online.php'

Upload all the files to your webserver, and this should work like a charm.


Thats all.

-Got Java?

Note: please post on my moparscape topic: http://moparscape.org/smf/index.php?action=post;msg=2259452;topic=277197.0;sesc=184f99281fc4c09bdbb6ae779c609a29
Share Report Spam   Logged
Ghost Rider
V++ Helper
Sr. Member
****

Rep: +42/-1
SG:
Posts: 117

general87@hotmail.com
View Profile Email
« Reply #1 on: June 09, 2008, 08:35:55 pm »

Nice,thx for the tut,i rep++ you.
Report Spam   Logged

V++ editor and coder.
Pages: [1]
  Print  
 
Jump to:  

Elaborate Search Engine

Directories
Yahoo
DMOZ
Snap

Search Engines
Alta Vista
Direct Hit
Lycos
Excite

Webcrawler
Go.com
DejaNews
Google
Meta Searches
Go2Net
Search.Com
Mamma
DogPile

Enter text to find:

AquaAngular was created by deathwilldie of Ultimate Graphics
Shoutbox
[Open]


Fill your Birth-Date in in the below fields

Month Day Year Hour



This is how long you live:

Months :
Weeks :
Days :
Hours :
Minutes :
Seconds :
Milliseconds :

Your next birthday is over:

Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2006-2009, Simple Machines LLC
Hostgator Hosting