点击登录
  • 欢迎访问无限星辰技术博客,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏无限星辰吧
  • 好集导航开张了,传送门:好集导航

独立统计在线人数和访问数代码分享(php)

PHP学习笔记 crx349 14094次浏览 0个评论 扫描二维码

代码有2张,和一个sql
1.conn_count.php

< ?php $host="localhost"; //请在双引号内填写你的mysql数据库主机 $root=""; //请在双引号内填写你的mysql数据库账号 $pw=""; //请在双引号内填写你的mysql数据库密码 $name=""; //请在双引号内填写你的mysql数据库名称 $link=mysql_connect($host,$root,$pw); mysql_select_db($name,$link); ?>

2.count.php
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns="http://www.w3.org/1999/xhtml">
< head>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< title>站内统计代码
< style type="text/css">
< !-- body { background-color: #ccc; } -- >
< /style>< /head>
< body>
< ?php require_once("conn_count.php"); $get_ip=$_SERVER['REMOTE_ADDR']; $date=date("Y-m-d"); $time=date("H:i:s"); $sel_ip=mysql_query("select * from ip where ip='$get_ip'"); $check=mysql_fetch_array($sel_ip); $check1=$check['ip']; if($check1==""){ mysql_query("insert into ip(ip,time) values ('$get_ip','$date')"); } $sel_str_ip=mysql_query("select id from ip"); $str_ip=mysql_num_rows($sel_str_ip);//ip总数 $today_sel_ip=mysql_query("select * from ip where time='$date'"); $today_ip=mysql_num_rows($today_sel_ip);//今日ip总数 mysql_query("update parameter set count=count+1,today=today+1"); $sel_count=mysql_query("select * from parameter"); $sel_tab=mysql_fetch_array($sel_count); $blog_count=$sel_tab['count'];//总访问量 $today_count=$sel_tab['today'];//今日访问量 $sel_date=mysql_query("select * from parameter where today_date='$date'"); $check_date=mysql_fetch_array($sel_date); $check_d=$check_date['today_date']; if($check_d!=$date){ mysql_query("update parameter set today_date='$date',today=1"); } $ip_sql=mysql_query("select ip from online where ip='$get_ip'"); if(!list($sel_old)=mysql_fetch_row($ip_sql)){ mysql_query("insert into online(ip,onlinetime) values ('$get_ip','$time')"); } $that_time=$sel_tab['time']; function conversec($datet){ $ip_h=intval(substr($datet,0,2)); $ip_m=intval(substr($datet,3,2)); $ip_s=intval(substr($datet,6,2)); $retval=$ip_h*3600+$ip_m*60+$ip_s; return $retval; } $tp=conversec($time); $tm=conversec($that_time); $ip_c=$tp-$tm; if($ip_c>1200 or $ip_c<0){ mysql_query("delete from online"); mysql_query("update parameter set time='$time'"); mysql_query("insert into online(ip,onlinetime) values ('$get_ip','$time')"); } $sel_now_ip=mysql_query("select id from online"); $now_ip=mysql_num_rows($sel_now_ip);//当前人数 $now_rand=rand(11,99); #echo "ip总数:".$str_ip."今日ip总数:".$today_ip."总访问量:".$blog_count."今日访问量:".$today_count."当前在线:".$now_ip; echo "您是第 ".$blog_count." 个来到本站的访客,当前火爆在线人数:".$now_ip.$now_rand."人!"; mysql_close(); ?>
< /body>
< /html>

3.sql
CREATE TABLE `ip` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ip` VARCHAR( 30 ) NOT NULL ,
`time` DATE NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci
CREATE TABLE `parameter` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`count` TEXT NOT NULL ,
`today` TEXT NOT NULL ,
`today_date` DATE NOT NULL ,
`time` TIME NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci
CREATE TABLE `online` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ip` VARCHAR( 19 ) NOT NULL ,
`onlinetime` TIME NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci
INSERT INTO `parameter` (
`id` ,
`count` ,
`today` ,
`today_date` ,
`time`
)
VALUES (
NULL , '1', '', '2011-06-21', '14:55:26'
);

sql分别运行 创建各表

4.调用方式
< iframe width="100%" height="30" src="count.php" scrolling="no" frameborder="0" marginheight="0" marginwidth="0">< /iframe>


无限星辰 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明独立统计在线人数和访问数代码分享(php)!
喜欢 (1)
[]
分享 (0)

您必须 登录 才能发表评论!