zoukankan      html  css  js  c++  java
  • 网站计数分析模块

    修改自《PHP模块大全》

    主页

    index.php

    在验证session里的某值是否为空时$_SESSION['temp']==NULL 放在 $_SESSION['temp']==""前面

    View Code
    <?php session_start(); include("conn/conn.php"); 
    $data1=date("Y-m-d"); //获取当前访问时间
    $data2=substr(date("Y-m-d"),0,7);
    $ip=getenv('REMOTE_ADDR');
    if($_SESSION['temp']==NULL || $_SESSION['temp']==""){ //判断$_SESSION['temp']==""的值是否为空,其中的'temp'为自定义的变量
    //使用数据库存储数据

    $select=mysql_query("select * from tb_count10 where data1='$data1' and ip='$ip'");
    if(mysql_num_rows($select)>0){

    $query1="update tb_count10 set counts=counts+1 where data1='$data1' and ip='$ip'";
    $result1=mysql_query($query1);
    }else{
    $query="insert into tb_count10(counts,data1,data2,ip)values('1','$data1','$data2','$ip')";
    $result=mysql_query($query);
    }
    $_SESSION['temp']=1; //登录以后,$_SESSION['temp']的值不为空,给$_SESSION['temp']赋一个值1
    }
    ?>
    <HTML>
    <HEAD>
    <TITLE>通过图形输出网站访问量</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
    <style type="text/css">
    <!--
    .STYLE1 {font-size: 12px}
    a:link {
    text-decoration: none;
    }
    a:visited {
    text-decoration: none;
    }
    a:hover {
    text-decoration: none;
    }
    a:active {
    text-decoration: none;
    }
    -->
    </style>
    </HEAD>
    <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
    <TABLE WIDTH=1003 BORDER=0 CELLPADDING=0 CELLSPACING=0>
    <TR>
    <TD background="images/bg3.jpg"><div align="center"><img src="images/bg.jpg" width="773" height="154"></div></TD>
    </TR>
    <TR>
    <TD height="32" background="images/bg1.jpg">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="STYLE1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <script language = "JavaScript" type = "text/javascript">
    var date_time=new Date(); //创建一个Date对象
    with(date_time){
    //定义变量,并为其赋值为当前年份,后加中文"年"字标识
    var date_times=getYear()+"年";
    //获取当前月份.注意月份从0开始,所以需加1,后加中文"月"标识
    date_times+=getMonth()+1+"月";
    date_times+=getDate()+"日"; //取当前日期,后加中文"日"标识
    date_times+=getHours()+":"; //获取当前小时
    date_times+=getMinutes()+":"; //获取当前分钟
    date_times+=getSeconds(); //获取当前秒数
    document.write(date_times); //输出结果
    }
    </script>
    </span></TD>
    </TR>
    <TR>
    <TD height="122" align="center" valign="top" background="images/bg3.jpg"><table width="1003" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td height="20">&nbsp;</td>
    <td height="20">&nbsp;</td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td width="165" height="110">&nbsp;</td>
    <td width="671" height="420"><p>&nbsp;<span class="STYLE1">&nbsp;吉林省明日科技有限公司是一家以计算机软件技术为核心的高科技型企业,公司创建于2000年12月,是专业的应</span></p>
    <p class="STYLE1">用软件开发商和服务提供商。多年来始终致力于行业管理软件开发、数字化出版物开发制作、计算机网络系统综合</p>
    <p class="STYLE1">应用、行业电子商务网站开发等领域,涉及生产、管理、控制、仓贮、物流、营销、服务等行业。公司拥有软件开</p>
    <p class="STYLE1">发和项目实施方面的资深专家和学习型技术团队,公司的开发团队不仅是开拓进取的技术实践者,更致力于成为技</p>
    <p class="STYLE1">术的普及和传播者,并以软件工程为指导思想建立了软件研发和销售服务体系。公司基于长期研发投入和丰富的行</p>
    <p class="STYLE1">业经验,本着 “ 让客户轻松工作,同客户共同成功 ” 的奋斗目标,努力发挥“ 专业、易用、高效 ” 的产品</p>
    <p class="STYLE1">优势,竭诚为广大用户提供优质的产品和服务。</p>
    <p class="STYLE1"><strong>企业宗旨</strong>:为企业服务,打造企业智能管理平台,改善企业的管理与运作过程,提高企业效率,降低管理成本,增</p>
    <p class="STYLE1">强企业核心竞争力。为企业快速发展提供源动力。</p>
    <p class="STYLE1"><strong>企业精神</strong>:博学、创新、求实、笃行</p>
    <p class="STYLE1"><strong>公司理念</strong>:以高新技术为依托,战略性地开发具有巨大市场潜力的高价值的产品。</p>
    <p class="STYLE1"><strong>公司远景</strong>:成为拥有核心技术和核心产品的高科技公司,在某些领域具有领先的市场地位。</p>
    <p class="STYLE1"><strong>核心价值观</strong>:永葆创业激情、每一天都在进步、容忍失败,鼓励创新、充分信任、平等交流。</p> </td>
    <td width="167">&nbsp;</td>
    </tr>
    <tr>
    <td height="20">&nbsp;</td>
    <td height="50" align="center">
    <?php
    //以图形的形式输出数据库中的记录数
    $query="select sum(counts) as ll from tb_count10 ";//查询数据库中总的访问量
    $result=mysql_query($query);
    $fwl=mysql_result($result,0,'ll');
    echo "----------";
    //对补位数字0的处理
    $len=strlen($fwl); //获取字符串的长度
    $str=str_repeat("0",6-$len); //获取6-$len个数字0
    for($i=0;$i<strlen($str);$i++){ //获取变量$str的字符串长度
    $result=$str[$i];
    $result='<img src=images/0.gif>';
    echo $result; //循环输出$result的结果
    }
    //对数据库中数据的处理
    for($i=0;$i<strlen($fwl);$i++){ //获取字符串的长度
    $result=$fwl[$i];
    switch($result){
    //如果值为"0",则输出0.gif图片
    case "0"; $ret[$i]="0.gif";break;
    case "1"; $ret[$i]="1.gif";break;
    case "2"; $ret[$i]="2.gif";break;
    case "3"; $ret[$i]="3.gif";break;
    case "4"; $ret[$i]="4.gif";break;
    case "5"; $ret[$i]="5.gif";break;
    case "6"; $ret[$i]="6.gif";break;
    case "7"; $ret[$i]="7.gif";break;
    case "8"; $ret[$i]="8.gif";break;
    case "9"; $ret[$i]="9.gif";break;
    }
    echo "<img src=images/".$ret[$i].".>"; //输出访问次数
    }
    ?>
    <a href="indexs.php" class="STYLE1">网站访问量统计分析</a> </td>
    <td>&nbsp;</td>
    </tr>
    </table></TD>
    </TR>
    <TR>
    <TD><img src="images/bg2.jpg" width=1003 height=48 ></TD>
    </TR>
    </TABLE>
    <form name="form1" method="post" action="indexs.php">
    <select name="select">
    <option value="2008-01">2008-01</option>
    <option value="2008-02">2008-02</option>
    <option value="2008-03">2008-03</option>
    <option value="2008-04">2008-04</option>
    </select>&nbsp;&nbsp;
    <input type="submit" name="Submit" value="提交">
    </form>
    </BODY>
    </HTML>



    显示图表页面

    indexs.php

    View Code
    <?php  include("conn/conn.php"); ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>网站访问量统计</title>
    <style type="text/css">
    <!--
    .STYLE2 {color: #0066FF;
    font-size: 12px}
    body {
    background-color: #515151;
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    }
    .STYLE4 {color: #000000;font-size: 12px}
    -->
    </style></head>
    <body>
    <table width="1003" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><img src="images/mysql1_8 (3).jpg" width="1003" height="79"></td>
    </tr>
    <tr>
    <td height="2"></td>
    </tr>
    <tr>
    <td><img src="images/mysql1_8 (4).jpg" width="1003" height="30"></td>
    </tr>
    <tr>
    <td width="1003" height="500" align="center" valign="top" bgcolor="#FFFFFF"><table width="950" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#A6D98C">
    <tr>
    <td bgcolor="#FFFFFF"><img src="images/mysql1_8.jpg" width="950" height="25"></td>
    </tr>
    <tr>
    <td height="400" align="center" valign="top" bgcolor="#FFFFFF"><table width="902" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#D5D5D5">
    <tr>
    <td bgcolor="#FFFFFF"><img src="images/mysql1_8 (1).jpg" width="902" height="18"></td>
    </tr>
    <tr>
    <td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="240" height="25" align="center" valign="middle">
    <?php
    $query_1="select sum(counts) as countes from tb_count10 ";
    //查询数据库中总的访问量
    $result_1=mysql_query($query_1);
    $countes_1=mysql_result($result_1,0,'countes');
    echo "<p class='STYLE1'>网站总的访问量:$countes_1</p>";
    //查询数据库中总的IP访问量
    $query_2="select * from tb_count10 ";
    $result_2=mysql_query($query_2);
    while($myrow=mysql_fetch_array($result_2)){
    $counts_2[]=$myrow['ip']; //将获取的ip的值赋给变量
    }
    $results_2=array_unique($counts_2); //去除数组中重复的值
    $countes_2=count($results_2); //获取数组中值的数量,即总的ip访问量
    echo "<p class='STYLE1'>网站总的IP访问量:$countes_2</p>";
    ?></td>
    <td width="240" align="center" valign="middle">
    <?php
    //查询数据库中当月总的访问量
    $query_3="select sum(counts) as countes from tb_count10 where data2='".substr(date("Y-m-d"),0,7)."'";
    $result_3=mysql_query($query_3);
    $countes_3=mysql_result($result_3,0,'countes');
    echo "<p class='STYLE2'>网站当月的访问量:$countes_3</p>";
    //查询数据库中当月的IP访问量
    $query_4="select * from tb_count10 where data2='".substr(date("Y-m-d"),0,7)."'";
    $result_4=mysql_query($query_4);
    while($myrow_4=mysql_fetch_array($result_4)){
    $counts_4[]=$myrow_4['ip']; //将获取的ip的值赋给变量
    }
    $results_4=array_unique($counts_4); //去除数组中重复的值
    $countes_4=count($results_4); //获取数组中值的数量,即总的ip访问量
    echo "<p class='STYLE2'>网站当月IP的访问量:$countes_4</p>";
    ?></td>
    <td width="248" align="center" valign="middle">
    <?php
    //查询数据库中当日总的访问量
    $query_5="select sum(counts) as countes from tb_count10 where data1='".date("Y-m-d")."' ";
    $result_5=mysql_query($query_5);
    $countes_5=mysql_result($result_5,0,'countes');
    echo "<p class='STYLE3'>网站当日的访问量:$countes_5</p>";
    //查询数据库中当日的IP访问量
    $query_6="select * from tb_count10 where data1='".date("Y-m-d")."'";
    $result_6=mysql_query($query_6);
    while($myrow_6=mysql_fetch_array($result_6)){
    $counts_6[]=$myrow_6['ip']; //将获取的ip的值赋给变量
    }
    if(is_array($counts_6)){
    $results_6=array_unique($counts_6); //去除数组中重复的值
    $countes_6=count($results_6); //获取数组中值的数量,即总的ip访问量
    echo "<p class='STYLE3'>网站当日IP的访问量:$countes_6</p>";
    }
    ?></td>
    </tr>
    </table>

    </td>
    </tr>
    </table>
    <?php
    $lmbs="1";
    $select=$_POST['select'];
    $query="select counts from tb_count10 where data2='$select' order by data1 ";
    $result=mysql_query($query);
    while($myrow=mysql_fetch_array($result)){
    $results[]=current($myrow);
    $lmbs=implode(",",$results);
    }
    if($lmbs==""){
    echo "";}else{
    ?>
    <table width="902" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#D5D5D5">
    <tr>
    <td height="18" background="images/mysql_9.jpg" bgcolor="#FFFFFF" class="STYLE4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_POST['select'];?>月网站访问量走势图</td>
    </tr>
    <tr>
    <td bgcolor="#FFFFFF"> <p><img src="stat.php?lmbs=<?php echo $lmbs?>"/></p>
    <p align="center" class="STYLE2"><?php echo $_POST['select'];?>月网站访问量走势图</p>
    </td>
    </tr>
    </table>

    <?php }?>


    </td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td><img src="images/mysql1_8 (2).jpg" width="1003" height="30"></td>
    </tr>
    </table>
    </body>
    </html>



    生成统计图页面

    stat.php

    用split分隔字符串生成数组会出错,改用explode

    <?php
    $img_height=300; //画布的高度
    $img_width=0; //画布宽度
    $img_space=27; //刻度之间的间隔
    $left=30; //左侧留出的宽度
    $right=30; //右侧留出的宽度
    $up=30; //上面留出的高度
    $down=30; //下面留出的高度
    $max=1; //最大数据值
    $p_x = array(); //数据的x轴坐标
    $p_y = array(); //数据的y轴坐标
    for($i=1;$i<=32;$i++){ //获取月份的值
    $month[]=$i;
    }
    $lmbs=$_GET['lmbs'];
    if ($lmbs=="") die("error id:0");
    $data=explode(",",$lmbs); //按照","分隔字符串 $data为获取的数据变量
    for($i=0;$i<count($data);$i++){
    if(!is_numeric($data[$i])) die("error id:1");//settype($data[$i],"integer");
    if($data[$i]>$max) $max=$data[$i]; }
    $img_width=$left+$right+count($data)*$img_space; //画布的真正宽度
    $image = imagecreate($img_width,$img_height); //创建画布
    $white = imagecolorallocate($image, 0xEE, 0xEE, 0xEE); //匹配颜色
    $left_color = imagecolorallocate($image, 0x00, 0x00, 0x00);
    $down_color = imagecolorallocate($image, 0x00, 0x00, 0xFF);

    imageline ( $image, $left, $img_height-$down, $img_width-$right/2, $img_height-$down, $left_color); //x轴坐标
    imageline ( $image, $left, $up/2, $left, $img_height-$down, $left_color); //y轴坐标

    //描述出数据在坐标上的点

    for($i=0;$i<count($data);$i++){
    array_push ($p_x, $left+$i*$img_space);
    array_push ($p_y, $up+round(($img_height-$up-$down)*(1-$data[$i]/$max))); }
    //输出y轴最高点的值
    imageline ( $image, $left, $up, $left+6, $up, $left_color);
    imagestring ( $image, 3, $left/4, $up,$max, $left_color);
    //输出y轴3/4高度的值
    imageline ( $image, $left, $up+($img_height-$up-$down)*1/4, $left+6, $up+($img_height-$up-$down)*1/4, $left_color);
    imagestring ( $image, 3, $left/4, $up+($img_height-$up-$down)*1/4,$max*3/4, $left_color);
    //输出y轴2/4高度的值
    imageline ( $image, $left, $up+($img_height-$up-$down)*2/4, $left+6, $up+($img_height-$up-$down)*2/4, $left_color);
    imagestring ( $image, 3, $left/4, $up+($img_height-$up-$down)*2/4,$max*2/4, $left_color);
    //输出y轴1/4高度的值
    imageline ( $image, $left, $up+($img_height-$up-$down)*3/4, $left+6, $up+($img_height-$up-$down)*3/4, $left_color);
    imagestring ( $image, 3, $left/4, $up+($img_height-$up-$down)*3/4,$max*1/4, $left_color);
    //输出x轴的刻度
    for($i=0;$i<count($data);$i++){
    imageline ( $image, $left+$i*$img_space, $img_height-$down, $left+$i*$img_space, $img_height-$down-6, $left_color);
    imagestring ( $image, 2, $left+$i*$img_space-$img_space/4, $up+($img_height-$up-$down)+2,$month[$i], $left_color); }
    $data_color_int=0;
    //为每个点的坐标连线
    for($i=0;$i<count($data);$i++){
    if($i+1<>count($data)){
    imageline ( $image, $p_x[$i], $p_y[$i], $p_x[$i+1], $p_y[$i+1], $down_color);
    imagefilledrectangle($image, $p_x[$i]-1, $p_y[$i]-1, $p_x[$i]+1, $p_y[$i]+1, $down_color); }
    }
    imagefilledrectangle($image, $p_x[count($data)-1]-1, $p_y[count($data)-1]-1, $p_x[count($data)-1]+1, $p_y[count($data)-1]+1, $down_color);
    //输出每个坐标点的数据值
    for($i=0;$i<count($data);$i++){
    imagestring ( $image, 3, $p_x[$i]+4, $p_y[$i]-12,$data[$i], $left_color); }
    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image); //释放图像资源
    ?>




  • 相关阅读:
    在某个点上弹出层
    根据表名、过程名、视图名查找对应的数据库
    js时间转换nan问题 兼容浏览器
    过滤html标记 以及 返回顶部
    自定义控件 加入include 报错 问题
    在有索引视图的表上新增、修改、删除 报错 set ARITHABORT 选项不对
    访微博代码
    兼容问题 链接不跳转
    js上下滚动代码
    onload问题
  • 原文地址:https://www.cnblogs.com/xchaos/p/2394427.html
Copyright © 2011-2022 走看看