mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\users\status.php on line 107
Code (PHP)
<?
$hostdb = "localhost";
// ??????????????????
$userdb = "";
$passdb = "";
$db_game = "";
mysql_connect($hostdb, $userdb, $passdb) or die("?????????????????????");
mysql_select_db($db_game) or die("????????????????????");
// mysql configuration. // ?????? ????????? ???? Login ??????????????????
$mysql_address = "localhost";
$mysql_user = "";
$mysql_pass = "";
$ragnarok_db = "";
// login server configuration.
$login_address = "127.0.0.1";
$login_port = 6900;
// character server configuration.
$char_address = "127.0.0.1";
$char_port = 6121;
// map server configuration.
$map_address = "127.0.0.1";
$map_port = 5121;
// main script. // ???????? Login Map Char
$l = @fsockopen($login_address, $login_port, $x, $y, 1);
$c = @fsockopen($char_address, $char_port, $x, $y, 1);
$m = @fsockopen($map_address, $map_port, $x, $y, 1);
if ($l) {
echo "Login : <font color=\"green\"> Online</font><br />";
}
else {
echo "Login : <font color=\"red\"> Offline</font><br />";
}
if ($c) {
echo "Char :<font color=\"green\"> Online</font><br />";
}
else {
echo "Char : <font color=\"red\"> Offline</font><br />";
}
if ($m) {
echo "Status : <font color=\"green\"> Online</font><br />";
}
else {
echo "Status : <font color=\"red\"> Ofline</font><br />";
}
class usersOnline {
var $timeout = 600;
var $count = 0;
function usersOnline () {
$this->timestamp = time();
$this->ip = $this->ipCheck();
$this->new_user();
$this->delete_user();
$this->count_users();
}
function ipCheck() {
/*
This function checks if user is coming behind proxy server. Why is this important?
If you have high traffic web site, it might happen that you receive lot of traffic
from the same proxy server (like AOL). In that case, the script would count them all as 1 user.
This function tryes to get real IP address.
Note that getenv() function doesn't work when PHP is running as ISAPI module
*/
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}
elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}
elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
}
elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function new_user() {
$insert = mysql_query ("INSERT INTO useronline(timestamp, ip) VALUES ('$this->timestamp', '$this->ip')");
}
function delete_user() {
$delete = mysql_query ("DELETE FROM useronline WHERE timestamp < ($this->timestamp - $this->timeout)");
}
function count_users() {
$count = mysql_num_rows(mysql_query("SELECT DISTINCT ip FROM useronline"));
return $count;
}
}
mysql_connect($mysql_address, $mysql_user, $mysql_pass);
@mysql_select_db($ragnarok_db);
$u = mysql_query("SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1");
// ???????? Users Online ???
echo "Game Online: ".mysql_result($u, 0)." Users<br />";
$visitors_online = new usersOnline();
// ??????? ????????
echo "Web Online: ".$visitors_online->count_users()." Users<br />";
$totalid = mysql_num_rows(mysql_query("SELECT * FROM `login`"));
// ????? id ???????
echo "All ID : ".$totalid. " Users";
mysql_close();
?>
Tag : PHP
Date :
2011-11-25 16:22:29
By :
ไอซ์
View :
741
Reply :
3
No. 1
Guest
เฉพาะส่วนตรงนี้อะครับ เข้ามาแก้
Code (PHP)
class usersOnline {
var $timeout = 600;
var $count = 0;
function usersOnline () {
$this->timestamp = time();
$this->ip = $this->ipCheck();
$this->new_user();
$this->delete_user();
$this->count_users();
}
function ipCheck() {
/*
This function checks if user is coming behind proxy server. Why is this important?
If you have high traffic web site, it might happen that you receive lot of traffic
from the same proxy server (like AOL). In that case, the script would count them all as 1 user.
This function tryes to get real IP address.
Note that getenv() function doesn't work when PHP is running as ISAPI module
*/
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}
elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}
elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
}
elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function new_user() {
$insert = mysql_query ("INSERT INTO useronline(timestamp, ip) VALUES ('$this->timestamp', '$this->ip')");
}
function delete_user() {
$delete = mysql_query ("DELETE FROM useronline WHERE timestamp < ($this->timestamp - $this->timeout)");
}
function count_users() {
$count = mysql_query ("SELECT DISTINCT ip FROM useronline");
if(!$count) {
echo mysql_error(); die();
}
$num = mysql_num_rows($count);
echo $num;
//$count = mysql_num_rows(mysql_query("SELECT DISTINCT ip FROM useronline"));
return $count;
}
}
mysql_connect($mysql_address, $mysql_user, $mysql_pass);
@mysql_select_db($ragnarok_db);
$u = mysql_query("SELECT COUNT(`char_id`) FROM `char` WHERE `online` = 1");
// ???????? Users Online ???
echo "Game Online: ".mysql_result($u, 0)." Users<br />";
$visitors_online = new usersOnline();
// ??????? ????????
echo "Web Online: ".$visitors_online->count_users()." Users<br />";
$totalid = mysql_num_rows(mysql_query("SELECT * FROM `login`"));
// ????? id ???????
echo "All ID : ".$totalid. " Users";
mysql_close();
?>