Server Statistics on WebSite. PHP?

Have you created a useful tool? or Do you want to get help building one? This is the right place!
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
J0Y
Posts: 73
Joined: Wed Dec 31, 2008 6:22 pm

Server Statistics on WebSite. PHP?

Post by J0Y » Thu Mar 04, 2010 8:10 am

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>

User avatar
rocoder
Posts: 66
Joined: Thu Feb 04, 2010 8:52 am

Re: Server Statistics on WebSite. PHP?

Post by rocoder » Thu Mar 04, 2010 10:46 am

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:
Image

User avatar
J0Y
Posts: 73
Joined: Wed Dec 31, 2008 6:22 pm

Re: Server Statistics on WebSite. PHP?

Post by J0Y » Thu Mar 04, 2010 11:15 am

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 ^^

User avatar
rocoder
Posts: 66
Joined: Thu Feb 04, 2010 8:52 am

Re: Server Statistics on WebSite. PHP?

Post by rocoder » Thu Mar 04, 2010 1:27 pm

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:
Image

User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Server Statistics on WebSite. PHP?

Post by jurchiks » Fri Mar 05, 2010 2:46 pm

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...
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.

User avatar
rocoder
Posts: 66
Joined: Thu Feb 04, 2010 8:52 am

Re: Server Statistics on WebSite. PHP?

Post by rocoder » Fri Mar 05, 2010 3:52 pm

google,com ;)
Image

User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Server Statistics on WebSite. PHP?

Post by jurchiks » Sat Mar 06, 2010 8:04 pm

i'm asking for an answer, not fuckoff
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.

User avatar
rocoder
Posts: 66
Joined: Thu Feb 04, 2010 8:52 am

Re: Server Statistics on WebSite. PHP?

Post by rocoder » Sat Mar 06, 2010 8:57 pm

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:
Image

User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Server Statistics on WebSite. PHP?

Post by jurchiks » Sat Mar 06, 2010 9:45 pm

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
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.

User avatar
janiii
L2j Veteran
L2j Veteran
Posts: 4269
Joined: Wed May 28, 2008 3:15 pm
Location: Slovakia

Re: Server Statistics on WebSite. PHP?

Post by janiii » Sun Mar 07, 2010 7:52 pm

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
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper
I don't give private support - PM will be ignored!

User avatar
jurchiks
Posts: 6769
Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe

Re: Server Statistics on WebSite. PHP?

Post by jurchiks » Sun Mar 07, 2010 9:33 pm

ok cool, thx :)
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.

User avatar
Nighthawk666
Posts: 1
Joined: Sun Oct 26, 2008 2:17 pm
Location: Germany
Contact:

Re: Server Statistics on WebSite. PHP?

Post by Nighthawk666 » Wed Mar 17, 2010 11:11 pm

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
L2J rocks!!!!

Delux
Posts: 4
Joined: Fri Apr 02, 2010 4:04 pm

Re: Server Statistics on WebSite. PHP?

Post by Delux » Fri Apr 02, 2010 6:32 pm

Very usefull share ! Ty

Attila
Posts: 441
Joined: Mon May 05, 2014 10:15 am

Re: Server Statistics on WebSite. PHP?

Post by Attila » Fri Jun 17, 2016 7:18 pm

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

Post Reply