10/10/2018, 10:04
có bác nào bít code đếm người đang online hông , giúp với
đang cần code đó mong mọi người giúp đỡ (không phải code đếm luot truy cap website dau với lại tránh nhán f5 nữa nha)
có thể cho mình xin thuat toán luon nha
có thể cho mình xin thuat toán luon nha
Bài liên quan
// Get online stats
$guests_online = mysql_query("SELECT * FROM online WHERE status = '0' && isonline = '1'");
$guests_online_number = mysql_num_rows($guests_online);
if ($memberlogin == '1') {
$members_online = mysql_query("SELECT * FROM online WHERE status = '1' && isonline = '1'");
$members_online_number = mysql_num_rows($members_online);
$total_online = $guests_online_number + $members_online_number;
$members_online_list = "";
if ($members_online_number > '0') {
$member_nr = "1";
while($members_row = mysql_fetch_array($members_online)) {
$mouserId = $members_row***91;'uid'***93;;
$mouserName = htmlentities($members_row***91;'username'***93;);
$members_online_list .= "<a href=\"".profileurl($mouserId,$mouserName)."\" target=\"_self\">".$mouserName."</a>";
if ($member_nr < $members_online_number) {
$members_online_list .= ", ";
$member_nr++;
}
}
}
} else {
$total_online = $guests_online_number;
}
mà cho mình hỏi luon , hong bít cách nào để tét dc chức nănng này vậy (nhà chỉ có 1 máy hic)
mới tạo datbase "count_online" với table "online" trong do co 2 feild (sử ung int) 'status' va 'isonline' voi 'isonline' dc làm khóa chính và tăng tự đông
viết file "count_online.php" như sau :
///////////////////////////////////
<?php
mysql_connect("localhost","root","");
mysql_select_db("count_online");
mysql_query('SET NAMES "UTF8"');
//$knknkn=mysql_connect("localhost","root","");
// Get online stats
$guests_online = mysql_query("SELECT * FROM online WHERE status = '0' && isonline = '1'");
$guests_online_number = mysql_num_rows($guests_online);
if ($memberlogin == '1') {
$members_online = mysql_query("SELECT * FROM online WHERE status = '1' && isonline = '1'");
$members_online_number = mysql_num_rows($members_online);
$total_online = $guests_online_number + $members_online_number;
$members_online_list = "";
if ($members_online_number > '0') {
$member_nr = "1";
while($members_row = mysql_fetch_array($members_online)) {
$mouserId = $members_row['uid'];
$mouserName = htmlentities($members_row['username']);
$members_online_list .= "<a href=\"".profileurl($mouserId,$mouserName)."\" target=\"_self\">".$mouserName."</a>";
if ($member_nr < $members_online_number) {
$members_online_list .= ", ";
$member_nr++;
}
}
}
} else {
$total_online = $guests_online_number;
}
echo $total_online."<hr>";
?>
/////////////////////////////////
khi chay file "count_online.php" chỉ ra số 1 đang bực vì không thể tét truc tiep dc , cái này phải co ban bè moi tét dc sao
http://getclicky.com
Demo : www.xemphim.tv (qc tý :d)
<?php
$timestamp = time();
$expiration = $timestamp - 900;
$current_day = date('j');
$delete_results = mysql_query("DELETE FROM online WHERE online_date != '$current_day'");
if($userStatus != '1'){
$guest_result = mysql_query("SELECT * FROM online WHERE ip = '$ipaddress' && status = '0'");
$guest_count = mysql_num_rows($guest_result);
$update_results = mysql_query("UPDATE online SET isonline='0' WHERE ip='$ipaddress' && status = '1'");
if($guest_count != '0'){
$online_result = mysql_query("UPDATE online SET timestamp = '$timestamp', online_date = '$current_day', isonline = '1' WHERE ip = '$ipaddress' && status = '0'");
} else {
$online_result = mysql_query("INSERT INTO online (timestamp,online_date,isonline,status,played,ip)".
"VALUES ('". $timestamp ."', '".$current_day."', '1', '0', '0', '". $ipaddress ."')");
}
} else {
$user_result = mysql_query("SELECT * FROM online WHERE uid = '$userId' && status = '1'");
$user_count = mysql_num_rows($user_result);
$update_results = mysql_query("UPDATE online SET isonline='0' WHERE ip='$ipaddress' && status = '0'");
if($user_count != '0'){
$online_result = mysql_query("UPDATE online SET timestamp = '$timestamp', online_date = '$current_day', isonline='1', ip='$ipaddress' WHERE uid = '$userId' && status = '1'");
} else {
$uuserName = escape_string($userName);
$online_result = mysql_query("INSERT INTO online (timestamp,online_date,isonline,status,played,ip,uid,username)".
"VALUES ('". $timestamp ."', '".$current_day."', '1', '1', '0', '". $ipaddress ."', '". $userId ."', '". $uuserName ."')");
}
}
$update_results = mysql_query("UPDATE online SET isonline = '0' WHERE timestamp < '$expiration'");
// Get online stats
$guests_online = mysql_query("SELECT * FROM online WHERE status = '0' && isonline = '1'");
$guests_online_number = mysql_num_rows($guests_online);
if ($memberlogin == '1') {
$members_online = mysql_query("SELECT * FROM online WHERE status = '1' && isonline = '1'");
$members_online_number = mysql_num_rows($members_online);
$total_online = $guests_online_number + $members_online_number;
$members_online_list = "";
if ($members_online_number > '0') {
$member_nr = "1";
while($members_row = mysql_fetch_array($members_online)) {
$mouserId = $members_row***91;'uid'***93;;
$mouserName = htmlentities($members_row***91;'username'***93;);
$members_online_list .= "<a href=\"".profileurl($mouserId,$mouserName)."\" target=\"_self\">".$mouserName."</a>";
if ($member_nr < $members_online_number) {
$members_online_list .= ", ";
$member_nr++;
}
}
}
} else {
$total_online = $guests_online_number;
}
?>
nói sai mong bỏ qua nha