Page 1 of 1

Server statistics on website [HELP NEEDED]

Posted: Wed Jul 28, 2010 5:40 am
by Xvad
Hello guys,
I have already downloaded many many scripts for online players, castle control, pvp/pk status, etc. but unfortunately non of them work for me. I spent days searching for the problem, but in vain. For example, take a look at this screen: http://img266.imageshack.us/img266/4631/topstatus.png
This happens when a configured "Top_Level" script is opened in Firefox.
Script itself looks like this:

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <title></title>    </head>    <body>        <?php//---------CONFIGS---------//$title="Created By Classic Team";  // Page Title Here$type="1"; //Type 1 $server="localhost"; // MySQL IP$user="root"; //MySQL Username$password="******"; //MySQL Password$database="l2jdb"; //MySQL Database$top="100"; //-----END OF CONFIGS-----//  if ($title) {print("<head><title>$title</title></head>");}else {print("<head><title>No Page Title</title></head>");}mysql_connect("$server", "$user", "$password") or die(mysql_error());mysql_select_db("$database") or die(mysql_error()); if($type == '1'){$result = mysql_query("SELECT char_name,level FROM characters where level>0 and accesslevel=0 order by level desc")or die(mysql_error());echo "<center><h3>Top $top Level Players</h3></center><table border=10 align=center><tr> <th>Character</th> <th>Level</th> </tr>";$sum1=0;while($row = mysql_fetch_array( $result )) {		$name = $row['char_name'];		$level = $row['level'];		if ($sum1<$top) {		echo "<tr><td align=center>$name</td><td align=center>$level</td></tr>";		$sum1++;		}	}} else {echo "<center>Please config the variable $type. Make it <b>1</b> for Top Status</center>";}?>    </body></html>
If you have any idea how to fix this issue, please let me know.
Thanks in advance

Re: Server statistics on website [HELP NEEDED]

Posted: Wed Jul 28, 2010 10:37 pm
by Probe
are you testing this on your computer or on the web server?
you need to have apache and php installed if on your computer
and make sure the file ends with .php (or any other extension your server knows to look for php at)

Re: Server statistics on website [HELP NEEDED]

Posted: Wed Jul 28, 2010 11:13 pm
by Zoey76
This is the fixed version of your script, tested.
As Probe said you need to save this as (whatever name you want) .php, top10.php
Also this script may flood your your server, since it does a connection to the DB every time someone request the list.
You should use an XML file to cache the list and cron jobs every X hours or with every server restart if its daily.

Code: Select all

<?PHP    $title = "by Zoey76";  // Page Title Here    $server = "localhost"; // MySQL IP    $user = "root"; //MySQL Username    $password = ""; //MySQL Password    $database = "l2jdb"; //MySQL Database    $top="10";?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">        <?        if (!empty($title))        {            print("<title>$title</title>");        }        else        {            print("<title>Top ".$top."</title>");        }        ?>    </head>    <body>        <?            mysql_connect("$server", "$user", "$password") or die(mysql_error());            mysql_select_db("$database") or die(mysql_error());            //added LIMIT to the query to avoid loading the whole list of char            $result = mysql_query("SELECT char_name, level FROM characters WHERE (level > 0) AND (accesslevel = 0) ORDER BY level DESC LIMIT $top") or die(mysql_error());             print "<center><h1>Top $top Level Players</h1><table><tr><th>Character</th><th>Level</th></tr>";            //improved iteration            while($char = mysql_fetch_array( $result ))            {                echo "<tr><td>".$char['char_name']."</td><td align=center>".$char['level']."</td></tr>";            }            //added end tab for table            print "</table></center>";            //added close db conection            mysql_close();        ?>    </body></html>

Re: Server statistics on website [HELP NEEDED]

Posted: Thu Jul 29, 2010 2:50 am
by Xvad
First of all I want to thank both of you for your replies. Now about the problem - it still exists.
Probe wrote:are you testing this on your computer or on the web server?
you need to have apache and php installed if on your computer
and make sure the file ends with .php (or any other extension your server knows to look for php at)
Can you be more specific, like from where to download apache or php and how to make it work. Although I don't think that this might be a problem as I tested these scripts from many different PCs, both mine and others, so how come that noone has this god damn apache and php? anyways, be kind and explain to me how to work with these things. Thanks
Zoey76 wrote:This is the fixed version of your script, tested.
As Probe said you need to save this as (whatever name you want) .php, top10.php
Also this script may flood your your server, since it does a connection to the DB every time someone request the list.
You should use an XML file to cache the list and cron jobs every X hours or with every server restart if its daily.

Code: Select all

<?PHP	$title = "by Zoey76";  // Page Title Here	$server = "localhost"; // MySQL IP	$user = "root"; //MySQL Username	$password = ""; //MySQL Password	$database = "l2jdb"; //MySQL Database	$top="10";?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>    <head>        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">		<?		if (!empty($title))		{			print("<title>$title</title>");		}		else		{			print("<title>Top ".$top."</title>");		}		?>    </head>    <body>        <?			mysql_connect("$server", "$user", "$password") or die(mysql_error());			mysql_select_db("$database") or die(mysql_error());			//added LIMIT to the query to avoid loading the whole list of char			$result = mysql_query("SELECT char_name, level FROM characters WHERE (level > 0) AND (accesslevel = 0) ORDER BY level DESC LIMIT $top") or die(mysql_error()); 			print "<center><h1>Top $top Level Players</h1><table><tr><th>Character</th><th>Level</th></tr>";			//improved iteration			while($char = mysql_fetch_array( $result ))			{				echo "<tr><td>".$char['char_name']."</td><td align=center>".$char['level']."</td></tr>";			}			//added end tab for table			print "</table></center>";			//added close db conection			mysql_close();		?>    </body></html>
I couldn't understand this part:
"Also this script may flood your your server, since it does a connection to the DB every time someone request the list.You should use an XML file to cache the list and cron jobs every X hours or with every server restart if its daily"
can you explain it in better way please and about your fixed script - I still have a problem with it, but somewhat different from the original. Here, take a look at this screen: http://img9.imageshack.us/img9/8331/sastd.png
Have any ideas what could cause it?

Re: Server statistics on website [HELP NEEDED]

Posted: Thu Jul 29, 2010 3:39 am
by Zoey76
You may want to read the following pages:

Web server
http://en.wikipedia.org/wiki/Web_server
Apache HTTP Server
http://en.wikipedia.org/wiki/Apache_HTTP_Server
PHP
http://en.wikipedia.org/wiki/PHP
LAMP
http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29

This is an example of a server software package:
http://www.appservnetwork.com/

A summary of all the above, you won't be able to use server side scripts (like php ones) without server software running in your PC.
Not every PC has such software, so you must install it to make it work.

If you use one package with Apache/PHP/MySQL try not to install MySQL if you already got MySQL installed for your l2j server.

About the flood thing, well every time you request info from a database, this action consume server resources.

Re: Server statistics on website [HELP NEEDED]

Posted: Thu Jul 29, 2010 8:48 pm
by Probe
if you're new to this stuff I recommend the xampp bundle
http://www.apachefriends.org/en/xampp-windows.html

Re: Server statistics on website [HELP NEEDED]

Posted: Thu Jul 29, 2010 9:10 pm
by jurchiks
I would never recommend the 3-in-1. It's much better to set those programs up separately and learn some configs at the same time than to install 3-in-1 and just run an executable. It might be a little harder (I, for one, had problems configuring php to work with apache, the installer didn't add the right lines in httpd.conf, but that was the ONLY problem ever), but it's worth it.

Re: Server statistics on website [HELP NEEDED]

Posted: Sun Aug 01, 2010 5:38 pm
by Xvad
The problem occured because of I was testing scripts on local machine without having apache and all the other necessary programs. Now when I have them, everything works fine. Thanks all of you for replying and helping.

Re: Server statistics on website [HELP NEEDED]

Posted: Mon Aug 02, 2010 4:14 pm
by Probe
you're welcome