Page 1 of 1

Server Statistics on WebSite. PHP?

Posted: Thu Mar 04, 2010 8:10 am
by J0Y
Hi, I am working on a website for my server and I want to have most statistic available to view on the site. But of course like always I have issues. I don't know much at all about php, I found this script that's supposed to show my server status (On or Offline). Its a php file and I have no idea where to put it, I have tried copying it to my website in html format but that just shows the whole script on the website. I have tried making a link to pointing to the php file but that does the same thing, Shows the whole script when you click the link. Any help would be appreciated, posted script below. Please no flaming, you don't have to remind me that I'm a newbie at this.

Code: Select all

<?php #Login Server$serverLip="127.0.0.1";$serverLport="2106"; #GameServer$serverGip="127.0.0.1";$serverGPort="7777"; #Database Host$databaseHost="127.0.0.1";$databaseLogin="your user";$databasePassword="your pass";$databaseName="your db";  ?> <?php #Login$flogin = @fsockopen ($serverLip,$serverLport, $errno, $errstr, 1);if ( $flogin )     $lstat = "<font color=#00FF00>ONLINE</font>"; else     $lstat = "<font color=#FF0000>OFFLINE</font>";  #Sieghardt$fgame2 = @fsockopen ($serverGip,$serverGPort, $errno, $errstr, 1);if ( $fgame2 )     $gstat2 = "<font color=#00FF00>ONLINE</font>"; else     $gstat2 = "<font color=#FF0000>OFFLINE</font>";   mysql_connect($databaseHost,$databaseLogin,$databasePassword) or die (mysql_error()); mysql_select_db($databaseName) or die(mysql_error());   //online kari$query = ("SELECT * FROM characters WHERE online=1 and accesslevel=0"); $result = mysql_query($query) or die(mysql_error()); $num2=mysql_numrows($result);$sum=$sum+$num2; //Alliance$query = ("SELECT * FROM clan_data WHERE ally_name!=\"\""); $result = mysql_query($query) or die(mysql_error()); $alliance2=mysql_numrows($result); //all characters $query = ("SELECT * FROM characters WHERE accesslevel>=0"); $result = mysql_query($query) or die(mysql_error()); $char2=mysql_numrows($result); //all GM characters $query = ("SELECT * FROM characters Where accesslevel > 99"); $result = mysql_query($query) or die(mysql_error()); $gmchar2=mysql_numrows($result); //all accounts $query = ("SELECT * FROM accounts WHERE access_level>=0"); $result = mysql_query($query) or die(mysql_error()); $accounts2=mysql_numrows($result); //Clan  $get_config_data="SELECT clan_id FROM clan_data"; $query = ("SELECT clan_id FROM clan_data WHERE clan_id>0"); $result = mysql_query($query) or die(mysql_error()); $clan2=mysql_numrows($result); //GM$quary = mysql_query ("SELECT char_name FROM characters WHERE accesslevel>100 AND online=1");while ($gmtitle2 = mysql_fetch_array ($quary)) {    $gmname2 = $gmtitle2["char_name"];}   //Titan$quary = mysql_query ("SELECT char_name FROM characters WHERE accesslevel=75 AND online=1");while ($titantitle2 = mysql_fetch_array ($quary)) {    $titanname2 = $titantitle2["char_name"];}  mysql_close();mysql_connect($databaseHost,$databaseLogin,$databasePassword) or die(mysql_error()); mysql_select_db($databaseName) or die(mysql_error()); ?> <html><head><title>MEDNet Lineage II - Kamael Szerver</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"></head><body><font color=#000000><span class="style3">Login:</span></font> <?php print ("$lstat"); ?><br><font color=#000000><span class="style3">Game:</span></font> <?php print ("$gstat2"); ?><br><font color=#000000><span class="style3">Online Players:</span></font> <font color=#ff0000><?php print ("$num2"); ?></font><br><font color=#000000><span class="style3">All Account:</span></font> <font color=#ff0000><?php print ("$accounts2"); ?></font><br><font color=#000000><span class="style3">All Characters:</span></font> <font color=#ff0000><?php print ("$char2"); ?></font><br><font color=#000000><span class="style3">All GM Characters:</span></font> <font color=#ff0000><?php print ("$gmchar2"); ?></font><br><font color=#000000><span class="style3">All Clan:</span></font> <font color=#ff0000><?php print ("$clan2"); ?></font><br><font color=#000000><span class="style3">All Alliance:</span></font> <font color=#ff0000><?php print ("$alliance2"); ?></font><br><font color=#000000><span class="style3">Online Titan:</span></font> <font color=#ff0000><?php print ("$titanname2"); ?></font><br><br><font color=#000000><span class="style3">Online GM:</span><br></font> <font color=#008800><?php print ("$gmname2"); ?></font><br></html>

Re: Server Statistics on WebSite. PHP?

Posted: Thu Mar 04, 2010 10:46 am
by rocoder
your script I think is ok (I just took a look and seems ok) just copy paste it in a .php file;)
Please no flaming, you don't have to remind me that I'm a newbie at this.
nobody will flame you because u dont know smthing...who will flame you will make that because u will run a l2 server:P without had enough knowledge :mrgreen:

Re: Server Statistics on WebSite. PHP?

Posted: Thu Mar 04, 2010 11:15 am
by J0Y
rocoder wrote:your script I think is ok (I just took a look and seems ok) just copy paste it in a .php file;)
Please no flaming, you don't have to remind me that I'm a newbie at this.
nobody will flame you because u dont know smthing...who will flame you will make that because u will run a l2 server:P without had enough knowledge :mrgreen:
Ok yeah I have it in a php file, but now what do I do with it? Thats the part im stuck at ^^

Re: Server Statistics on WebSite. PHP?

Posted: Thu Mar 04, 2010 1:27 pm
by rocoder
upload in a host;))(or test on your pc with a apache(php) server) btw hope u changed the ips;)) for gs and login :mrgreen:

Re: Server Statistics on WebSite. PHP?

Posted: Fri Mar 05, 2010 2:46 pm
by jurchiks
heh, my server has almost the same script for db access...
i have a question of my own too
i'd like the script to access 2 databases
i tried connecting just to the mysql, without the
mysql_select_db($databaseName) or die(mysql_error());
not working
tried using
$query = ("SELECT * FROM lowrate.characters WHERE online=1 and accesslevel=0");
not working
how could i get the script to read data from 2 databases (both on 1 pc)?
the loginserver shares db with 1 gameserver, no problem there, but i want it to read the other db too...
currently it has 2 scripts for both databases, which IMO sucks...

Re: Server Statistics on WebSite. PHP?

Posted: Fri Mar 05, 2010 3:52 pm
by rocoder
google,com ;)

Re: Server Statistics on WebSite. PHP?

Posted: Sat Mar 06, 2010 8:04 pm
by jurchiks
i'm asking for an answer, not fuckoff

Re: Server Statistics on WebSite. PHP?

Posted: Sat Mar 06, 2010 8:57 pm
by rocoder
I can explain what u want:P but I wont write the code for u:P the main idea is to connect to db1 and update it with what u want after that close connection, after that connect to db2 update it close connection:P
:mrgreen:

Re: Server Statistics on WebSite. PHP?

Posted: Sat Mar 06, 2010 9:45 pm
by jurchiks
ok, ill try that
i don't need to update them though, just read info, and since they're both on 1 pc i thought maybe there is a way to make it work with single connection for both databases

Re: Server Statistics on WebSite. PHP?

Posted: Sun Mar 07, 2010 7:52 pm
by janiii
jurchiks wrote:heh, my server has almost the same script for db access...
i have a question of my own too
i'd like the script to access 2 databases
i tried connecting just to the mysql, without the
mysql_select_db($databaseName) or die(mysql_error());
not working
tried using
$query = ("SELECT * FROM lowrate.characters WHERE online=1 and accesslevel=0");
not working
how could i get the script to read data from 2 databases (both on 1 pc)?
the loginserver shares db with 1 gameserver, no problem there, but i want it to read the other db too...
currently it has 2 scripts for both databases, which IMO sucks...
http://stackoverflow.com/questions/2748 ... 919#274919

Re: Server Statistics on WebSite. PHP?

Posted: Sun Mar 07, 2010 9:33 pm
by jurchiks
ok cool, thx :)

Re: Server Statistics on WebSite. PHP?

Posted: Wed Mar 17, 2010 11:11 pm
by Nighthawk666
Nice Script :D , thanx !!!

I changed the Colors to my defaults and i have added the Community Server "Online" Status.

Here is the Code:

Code: Select all

 <?php   #Login Server $serverLip="127.0.0.1"; $serverLport="2106";   #GameServer $serverGip="127.0.0.1"; $serverGPort="7777"; #Community Server $servercom="127.0.0.1"; $servercport="9013";  #Database Host $databaseHost="127.0.0.1"; $databaseLogin="root"; $databasePassword="yourdb pw"; $databaseName="L2jDB";  #Server Ip #$address = getenv("REMOTE_ADDR");##echo $address;#// Or simply use a Superglobal ($_SERVER or $_ENV)##$ip = $_SERVER['REMOTE_ADDR'];$ip = gethostbyname('[color=#BF0000]your Homepagename[/color]'); ?>   <?php   #Login $flogin = @fsockopen ($serverLip,$serverLport, $errno, $errstr, 1); if ( $flogin )      $lstat = "<font color=#00FF00>ONLINE</font>";  else      $lstat = "<font color=#FF0000>OFFLINE</font>";     #Sieghardt $fgame2 = @fsockopen ($serverGip,$serverGPort, $errno, $errstr, 1); if ( $fgame2 )      $gstat2 = "<font color=#00FF00>ONLINE</font>";  else      $gstat2 = "<font color=#FF0000>OFFLINE</font>";    #Community Server$fcom = @fsockopen ($servercom, $servercport, $errno, $errstr, 1); mysql_connect($databaseHost,$databaseLogin,$databasePassword) or die (mysql_error()); if ( $fcom )      $comstat = "<font color=#00FF00>ONLINE</font>";  else      $comstat = "<font color=#FF0000>OFFLINE</font>";  mysql_select_db($databaseName) or die(mysql_error());     //online kari $query = ("SELECT * FROM characters WHERE online=1 and accesslevel=0");   $result = mysql_query($query) or die(mysql_error());   $num2=mysql_numrows($result); $sum=$sum+$num2;   //Alliance $query = ("SELECT * FROM clan_data WHERE ally_name!=\"\"");   $result = mysql_query($query) or die(mysql_error());   $alliance2=mysql_numrows($result);   //all characters   $query = ("SELECT * FROM characters WHERE accesslevel>=0");   $result = mysql_query($query) or die(mysql_error());   $char2=mysql_numrows($result);   //all GM characters   $query = ("SELECT * FROM characters Where accesslevel > 99");   $result = mysql_query($query) or die(mysql_error());   $gmchar2=mysql_numrows($result);   //all accounts   $query = ("SELECT * FROM accounts WHERE accesslevel>=0");   $result = mysql_query($query) or die(mysql_error());   $accounts2=mysql_numrows($result);   //Clan     $get_config_data="SELECT clan_id FROM clan_data";   $query = ("SELECT clan_id FROM clan_data WHERE clan_id>0");   $result = mysql_query($query) or die(mysql_error());   $clan2=mysql_numrows($result);   //GM $quary = mysql_query ("SELECT char_name FROM characters WHERE accesslevel>100 AND online=1"); while ($gmtitle2 = mysql_fetch_array ($quary)) {     $gmname2 = $gmtitle2["char_name"]; }       //Titan $quary = mysql_query ("SELECT char_name FROM characters WHERE accesslevel=75 AND online=1"); while ($titantitle2 = mysql_fetch_array ($quary)) {     $titanname2 = $titantitle2["char_name"]; }     mysql_close(); mysql_connect($databaseHost,$databaseLogin,$databasePassword) or die(mysql_error());   mysql_select_db($databaseName) or die(mysql_error());   ?>   <html> <head> <title>MEDNet Lineage II - Kamael Szerver</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"> </head> <body> <font color=#ff9933><span class="style3">Login:</span></font> <?php print ("$lstat"); ?><br> <font color=#ff9933><span class="style3">Game:</span></font> <?php print ("$gstat2"); ?><br> <font color=#ff9933><span class="style3">Community:</span></font> <?php print ("$comstat"); ?><br> <br> <font color=#ff9933><span class="style3">Server IP:</span></font> <font color=#ff0000><?php print ("$ip"); ?></font><br><br> <font color=#ff9933><span class="style3">Spieler online:</span></font> <font color=#ff0000><?php print ("$num2"); ?></font><br> <br> <font color=#ff9933><span class="style3">Accounts:</span></font> <font color=#ff0000><?php print ("$accounts2"); ?></font><br> <font color=#ff9933><span class="style3">Characters:</span></font> <font color=#ff0000><?php print ("$char2"); ?></font><br> <font color=#ff9933><span class="style3">GM Characters:</span></font> <font color=#ff0000><?php print ("$gmchar2"); ?></font><br> <font color=#ff9933><span class="style3">Clans:</span></font> <font color=#ff0000><?php print ("$clan2"); ?></font><br> <font color=#ff9933><span class="style3">Allianzen:</span></font> <font color=#ff0000><?php print ("$alliance2"); ?></font><br> <font color=#ff9933><span class="style3">Online Titan:</span></font> <font color=#ff0000><?php print ("$titanname2"); ?></font><br><br> <font color=#ff9933><span class="style3">Online GM:</span><br></font> <font color=#ff0000><?php print ("$gmname2"); ?></font><br> </html> 
Where the red Letters are, u must change to your homepage address for example http://www.test.info. , where ur Gameserver and ur login server is hosted. So u and ur Player can see the address from ur gameserver Ip what must be changed in the windows host file.

Image


Sorry for my bad englisch :oops:

Nighthawk

Re: Server Statistics on WebSite. PHP?

Posted: Fri Apr 02, 2010 6:32 pm
by Delux
Very usefull share ! Ty

Re: Server Statistics on WebSite. PHP?

Posted: Fri Jun 17, 2016 7:18 pm
by Attila
How can i make It so you see more then 1 Gm online
<font color=#000000><span class="style3">Online GM:</span><br></font> <font color=#008800><?php print ("$gmname2"); ?></font><br>
if there are 2 gm online you see only 1 name and not 2
thanks