Home >Backend Development >PHP Tutorial >PHP system traffic analysis program_PHP tutorial
>create table stream ( ';
ip text,
sTime int,
visits int,
info text);
if($day<0)$day= 0;
$mlink=mysql_connect('localhost','ajax','xxxxxxx');
//Count the total number of times the homepage has been viewed so far
$query="select SUM(visits) as tvisits from stream";
$result=mysql_db_query('ajax',$query,$mlink);
echo 'Total cumulative number of visits to the homepage:';
if($row=mysql_fetch_object($result)){
echo $row->tvisits;
}
$week=array("Sunday","Monday"," Tuesday","Wednesday","Thursday","Friday","Saturday");
for($i=0;$i<=$day;$i++){
echo '
$ctime1=time()-24*3600*$i;
$ctime2=time()-24*3600*($i-1);
echo 'Date:'.date("m月d日",$ctime1).$week[date("w",$ctime1)];
echo "";
$stoday1=mktime(0,0,0,date(m,$ctime1),date(d,$ctime1),date(Y,$ctime1));
$stoday2=mktime(0, 0,0,date(m,$ctime2),date(d,$ctime2),date(Y,$ctime2));
//Count the cumulative number of times the homepage was viewed on that day
$query='select SUM(visits) as tvisits from stream where sTime>=';
$query.=$stoday1.' and sTime<'.$stoday2;
$result=mysql_db_query('ajax',$query,$mlink ;
}
//Count the number of IP visits on the day
$query='select * from stream where sTime>='.$stoday1;
$query.=' and sTime<'.$stoday2 .' order by sTime DESC';
$result=mysql_db_query('ajax',$query,$mlink);
echo "
Total number of viewers:".mysql_num_rows($result);
echo '
IP address | Latest time | Times | User information | ';
'.date("h:i:sa",$row->sTime). ' | ';'.$row->visits.' | ';'.$row- >info.' | ';