当前位置: 移动技术网 > IT编程>开发语言>PHP > CI(CodeIgniter)简单统计访问人数实现方法 原创

CI(CodeIgniter)简单统计访问人数实现方法 原创

2017年12月12日  | 移动技术网IT编程  | 我要评论

本文实例讲述了ci(codeigniter)简单统计访问人数实现方法。分享给大家供大家参考,具体如下:

废话不说,先上代码:

控制器文件:

/application/controllers/hello.php 如下:

<?php if ( ! defined('basepath')) exit('no direct script access allowed');
class hello extends ci_controller {
  public function index()
  {
    echo "hello codeigniter!";
  }
  public function showval($name){
    //访问路径:http://localhost/ci/index.php/hello/showval/tom
    $this->name=$name;
    @$num=file_get_contents('./num.txt');//加上@屏蔽警告提示(第一次运行没有txt文件会有警告提示)
    $num=$num?$num:0;
    $num++;
    $arr=array('v_name'=>$name,'v_num'=>$num);
    $re=fopen('./num.txt','w');
    fwrite($re,$num);
    fclose($re);
    $this->load->view('test_views',$arr);
  }
}

视图文件:

/application/views/test_views.php 如下:

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>访问统计</title>
</head>
<body>
<?php echo $v_name;?>是第 <?php echo $v_num;?> 位访问者
</body>
</html>

运行结果如下图所示:

更多关于codeigniter框架相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程

希望本文所述对大家基于codeigniter框架的php程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网