PHP website

02/06/2012 22:16 buzz2289#1
for some reason, i got my PHP website working (thanks to idlemonkey) but the part that says "players online" doesn't it always says 0 online, can someone help me?
02/06/2012 22:42 PowerChaos#2
Thats because that script works with netstat

it checks your connection to the server and count those connections on a certain port
if your website is not hosted localy then it wont work

here is a other script that shows online users , but based on the database and can be used remote

[Only registered and activated users can see links. Click Here To Register...]

Greetings From PowerChaos
02/06/2012 22:55 buzz2289#3
i don' have a online.php but now it tells me "Parse error: parse error in C:\xampp\htdocs\config.php on line 6"
02/06/2012 23:01 Eurion#4
I have no idea what made people start charging for simple fixes, but eh here's how to do the same thing but for free.


If all you want is to show the total amount of players currently online this will work.

Code:
$host = '127.0.0.1'; //Your db ip
$user = 'eurion'; //Your db username
$pass = 'test'; //Your db password
$con = mysql_connect($host, $user, $pass); //Connects to the db  
mysql_select_db("my"); //Selects your db
$players = mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout ORDER by Login_time desc");
$num = mysql_num_rows($players);//Grabs the total amount of rows
echo "Players Online: $num";
mysql_close($con);
Now if you want to show staff online. Something like this would work

Code:
$host = '127.0.0.1'; //Your db ip
$user = 'eurion'; //Your db username
$pass = 'test'; //Your db password
$con = mysql_connect($host, $user, $pass); //Connects to the db 
mysql_select_db("my"); //Selects your db 
$staff = mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout AND name LIKE '%[GM]%' OR Login_time > last_logout AND name LIKE '%[PM]%' OR Login_time > last_logout AND name LIKE '%[GH]%' ORDER BY Login_time DESC");
$staff_num = mysql_num_rows($staff);
echo "Staff Online: $staff";
mysql_close($con);

Pretty simple stuff once you start looking through the tables. Also note that if your mysql or server crashes, sometimes it can mess up the numbers. If that happens just run the following in a query

Code:
UPDATE cq_user SET Login_time='0';
That should be all you need.
02/06/2012 23:06 PowerChaos#5
that script is released for free o.O (see bottom of donwload page , changelog is just big )

only the cp is charged , other script not

its only encoded because i do not like it that other users will use my code for other things

Greetings From powerChaos
02/06/2012 23:07 buzz2289#6
ok you actually look like you know it, his codes are defunct and jibberish, here is my stats.ini (where my online offline is) do i just erase and put yours in?
Quote:
<?
require("config.php");
?>
<td align="left"><p><?php
mysql_select_db($mydbacc);
$res = mysql_query("SELECT count(*) FROM account;");
$val = mysql_fetch_array($res);
echo "Total Accounts: ".$val[0]."<br />";

mysql_select_db($mydbdata);
$res = mysql_query("SELECT count(*) FROM cq_user;");
$val = mysql_fetch_array($res);
echo "Total Characters: ".$val[0]."<br />";
$command="netstat -n -p tcp |find \"ESTABLISHED\"|find \":5816\" /c"; $output=shell_exec($command); echo "Players Online: ".($output)."<br/>\n";
echo "Server Status: ";
$fp = @fsockopen($serveraddress, $serverport, $errno, $errstr, 1);
if (!$fp) {
echo "<font style='color: maroon'><B>Offline</B></font></br>";
}
else
{
echo "<font style='color: lime'><B>Online</B></font></br>";
fclose($fp);
}
?>
02/06/2012 23:09 Eurion#7
Quote:
Originally Posted by PowerChaos View Post
that script is released for free o.O (see bottom of donwload page , changelog is just big )

only the cp is charged , other script not

its only encoded because i do not like it that other users will use my code for other things

Greetings From powerChaos
Encoding PHP leads many people not to use a script. It's too easy to inject malicious code. That is the reason why I went ahead and gave out the scripts I've had for a while.




Edit

That code's just sloppy. Here's my quick version of it. If anything goes wrong, feel free to leave a post and ill look at it.

Code:
<?php 
require("config.php");
?>
<td align="left"><p>
<?php
mysql_select_db($mydbacc);
$res = mysql_query("SELECT * FROM account;");
$val = mysql_num_rows($res);
echo "Total Accounts: ".$val."<br />";

mysql_select_db($mydbdata);
$players = mysql_query("SELECT * FROM cq_user;");
$playnum = mysql_num_rows($players);
echo "Total Characters: ".$playnum."<br />";
$player = mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout ORDER by Login_time desc");
$num = mysql_num_rows($player);//Grabs the total amount of rows
echo "Players Online: $num <br />";
echo "Server Status: ";
$fp = @fsockopen($serveraddress, $serverport, $errno, $errstr, 1);
if (!$fp) {
echo "<font style='color: maroon'><B>Offline</B></font></br>";
}
else
{
echo "<font style='color: lime'><B>Online</B></font></br>";
fclose($fp);
}
?>
02/06/2012 23:15 buzz2289#8
i got it :) in my stats code i replace the port and changed it to 3306, now it shows out, Eurion your code lead me o this so i thank you and clicked

$fp = @fsockopen($serveraddress, $serverport, $errno, $errstr, 1); is this where i add IP and ports? cause i don't see where to add dbuser, dbpass, ip, port? my website is on a different pc than my server
02/06/2012 23:26 PowerChaos#9
ok eoin
lets suggest a few fixes and here is the base code you need

if server is offline
PHP Code:
mysql_query("UPDATE cq_user SET last_logout='".$date."' WHERE cq_user.last_logout < cq_user.login_time"); 
if server is online
PHP Code:
$sql2 "SELECT * FROM cq_user WHERE cq_user.last_logout < cq_user.login_time"
as the so hard to find sql code is already released now ( i wanted to keep it a secret) is here atleast the good code

lets explain
login = when user logs in
logout = when user logs out

login get changed on every connect
logout get only changed if the user press logout (and if mysql is running , server crash = login stays above logout )

Greetings From PowerChaos
02/06/2012 23:29 buzz2289#10
eurion you code worked! i now have it up :) any way to show specific staff online? like Buzz[PM]: online/offline?
02/06/2012 23:34 PowerChaos#11
PHP Code:
<?php 
require("config.php");
?>
<td align="left"><p>
<?php
mysql_select_db
($mydbacc);
$res mysql_query("SELECT * FROM account;");
$val mysql_num_rows($res);
echo 
"Total Accounts: ".$val."<br />";

mysql_select_db($mydbdata);
$players mysql_query("SELECT * FROM cq_user;");
$playnum mysql_num_rows($players);
echo 
"Total Characters: ".$playnum."<br />";
$player mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout ORDER by Login_time desc");
$num mysql_num_rows($player);//Grabs the total amount of rows
echo "Players Online: $num <br />";
$staff mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout AND name LIKE 'Buzz[PM]' ORDER BY Login_time DESC");
$staff_num mysql_num_rows($staff);
if (
$staff_num == "1"){
echo 
"Buzz[PM] is Online </ br>";
}
else
{
echo 
"Buzz[PM] is Offline </ br>";
}
echo 
"Server Status: ";
$fp = @fsockopen($serveraddress$serverport$errno$errstr1);
if (!
$fp) {
echo 
"<font style='color: maroon'><B>Offline</B></font></br>";
}
else
{
echo 
"<font style='color: lime'><B>Online</B></font></br>";
fclose($fp);
}
?>
here you go
it will show buzz[pm] online or offline

Greetings From PowerChaos
02/06/2012 23:40 buzz2289#12
now where do i add my user name in all this?
Quote:
mysql_query("UPDATE cq_user SET last_logout='".$date."' WHERE cq_user.last_logout < cq_user.login_time");
if server is online
PHP Code:
$sql2 = "SELECT * FROM cq_user WHERE cq_user.last_logout < cq_user.login_time";
on the site i want it to say Buzz[PM]: Online
02/06/2012 23:42 PowerChaos#13
Quote:
Originally Posted by buzz2289 View Post
now where do i add my user name in all this?

on the site i want it to say Buzz[PM]: Online
PHP Code:
$staff mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout AND name LIKE 'Buzz[PM]' ORDER BY Login_time DESC"); // Edit here your name ...
$staff_num mysql_num_rows($staff);
if (
$staff_num == "1"){
echo 
"Buzz[PM] is Online";
}
else
{
echo 
"Buzz[PM] is Offline";

that other code is just the base code to update the users if the server is offline and to know where to get the online users from (so its meant for some1 who know what to edit)

Greetings From PowerChaos
02/06/2012 23:49 buzz2289#14
Quote:
Total Accounts: 8
Total Characters: 15
Players Online: 1
Server Status: Online
$staff = mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout AND name LIKE 'Buzz[PM]' ORDER BY Login_time DESC"); // Edit here your name ... $staff_num = mysql_num_rows($staff); if ($staff_num == "1"){ echo "Buzz[PM] is Online"; } else { echo "Buzz[PM] is Offline";
thats the result in the:
Quote:
$staff = mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout AND name LIKE 'Buzz[PM]' ORDER BY Login_time DESC"); // Edit here your name ...
$staff_num = mysql_num_rows($staff);
if ($staff_num == "1"){
echo "Buzz[PM] is Online";
}
else
{
echo "Buzz[PM] is Offline";
}
02/06/2012 23:51 PowerChaos#15
Quote:
Originally Posted by PowerChaos View Post
PHP Code:
<?php 
require("config.php");
?>
<td align="left"><p>
<?php
mysql_select_db
($mydbacc);
$res mysql_query("SELECT * FROM account;");
$val mysql_num_rows($res);
echo 
"Total Accounts: ".$val."<br />";

mysql_select_db($mydbdata);
$players mysql_query("SELECT * FROM cq_user;");
$playnum mysql_num_rows($players);
echo 
"Total Characters: ".$playnum."<br />";
$player mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout ORDER by Login_time desc");
$num mysql_num_rows($player);//Grabs the total amount of rows
echo "Players Online: $num <br />";
$staff mysql_query("SELECT * FROM cq_user WHERE Login_time > last_logout AND name LIKE 'Buzz[PM]' ORDER BY Login_time DESC");
$staff_num mysql_num_rows($staff);
if (
$staff_num == "1"){
echo 
"Buzz[PM] is Online </ br>";
}
else
{
echo 
"Buzz[PM] is Offline </ br>";
}
echo 
"Server Status: ";
$fp = @fsockopen($serveraddress$serverport$errno$errstr1);
if (!
$fp) {
echo 
"<font style='color: maroon'><B>Offline</B></font></br>";
}
else
{
echo 
"<font style='color: lime'><B>Online</B></font></br>";
fclose($fp);
}
?>
here you go
it will show buzz[pm] online or offline

Greetings From PowerChaos
go to that post
and use that form there

its the same form exept that i added the code in it

it is php code .. not html code

Greetings From PowerChaos