• Downloading from our site will require you to have a paid membership. Upgrade to a Premium Membership from 10$ a month today!

    Dont forget read our Rules! Also anyone caught Sharing this content will be banned. By using this site you are agreeing to our rules so read them. Saying I did not know is simply not an excuse! You have been warned.

Hướng dẫn tạo bộ đếm khách hôm nay, tổng lượt khách, online đơn giản

Admin

Well-Known Member
Staff member
Administrator
Tạo database .
PHP:
CREATE TABLE IF NOT EXISTS `user` (
  `id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `time` date DEFAULT '0000-00-00',
  `hit` int(10) unsigned NOT NULL DEFAULT '0',
  `hittoday` smallint(5) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;
insert into user (id, hit, hittoday) values ('1','0','0');
PHP:
CREATE TABLE user_online (
  session char(100) NOT NULL default '',
  time int(11) NOT NULL default '0',
  user_ip varchar(20) NOT NULL,
  user_browser varchar(200) NOT NULL,
  user_location varchar(200) NOT NULL
) TYPE=MyISAM
Mở file func.php hoặc function.php tùy mã nguồn mà vận dụng
Thêm cái này vào
PHP:
function visit($ur) //User online, hits today dan total hits
{
$session=session_id();
$time=time();
$time_check=$time-400;
$result=mysql_query("SELECT * FROM user_online WHERE user_ip='{$_SERVER['REMOTE_ADDR']}'");
$count=mysql_num_rows($result);
if($count=="0")
{
$_SERVER['HTTP_USER_AGENT']=strip_tags(addslashes($_SERVER['HTTP_USER_AGENT']));
$result1=mysql_query("INSERT INTO user_online (session, time, user_ip, user_browser, user_location) VALUES('$session', '$time', '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_USER_AGENT']}', '{$_SERVER['REQUEST_URI']}')");
}
else
{
$_SERVER['HTTP_USER_AGENT']=strip_tags(addslashes($_SERVER['HTTP_USER_AGENT']));
$result2=mysql_query("UPDATE user_online SET time='$time', user_ip='{$_SERVER['REMOTE_ADDR']}', user_browser='{$_SERVER['HTTP_USER_AGENT']}', user_location='{$_SERVER['REQUEST_URI']}' WHERE session = '$session'");
}
$result3=mysql_query("SELECT * FROM user_online");
$user_online=mysql_num_rows($result3);
$result4=mysql_query("DELETE FROM user_online WHERE time<$time_check");
if(!isset($_SESSION['user']) && !eregi('bot',$_SERVER['HTTP_USER_AGENT']))
{
mysql_query("update caidat set hittoday=hittoday+1, hit=hit+1 where id='1'");
}
echo '<div class="visit"><small><a href="'/index.php?whos" target="_blank">'.$user_online.'</a> Online | Today: '.$ur['hittoday'].' visit | Total: '.$ur['hit'].' visit</small></div>
';
}
Mở file config.php hoặc file kết nối với cơ sở dữ liệu
thêm vào
PHP:
$set = mysql_fetch_array(mysql_query("select * from user"));
mysql_query("set time_zone='+07:00'") or die(mysql_error());
mysql_query('SET NAMES `utf8`');
if(gmdate("Y-m-d", time()+25200) > $set["time"])
{
mysql_query("update caidat set time=now(),  hittoday='0' where id='1'") or die(mysql_error());
}
Mở files index.php
Chèn cái này
PHP:
if(isset($_GET['whos']))
{
$tit="Who is Online | Tuoitrevn.Biz";
echo '<b>AI đang trực tuyến</b>';
$arr=mysql_query("select * from user_online order by user_ip") or die(mysql_error());
while($ero=mysql_fetch_array($arr))
{
$location=$ero['user_location'];
$ero['user_browser']=strip_tags($ero['user_browser']);
if($ero['user_location']=="/") $ero['user_location']="Home";
echo '<div class="quoted">'.$ero['user_ip'].'<br>
'.$ero['user_browser'].'<br>
on <a href="'.$ero['user_location'].'">'.$ero['user_location'].'</a></div>';
}
}
Demo : đây
Code này mình hướng dẫn là chung nên không nói cụ thể mã nguồn nào được
Nguồn DVPDA
 

Facebook Comments

Similar threads

New posts New threads New resources

Back
Top