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?
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
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?
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);
}
?>
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
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 )
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";
$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)
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";
}