Home > Backend Development > PHP Tutorial > CI (CodeIgniter) simple method to count the number of visitors. Original, cicodeigniter_PHP tutorial

CI (CodeIgniter) simple method to count the number of visitors. Original, cicodeigniter_PHP tutorial

WBOY
Release: 2016-07-12 09:00:28
Original
1091 people have browsed it

CI (CodeIgniter) simple statistical visitor count implementation method Original, cicodeigniter

This article describes the CI (CodeIgniter) simple statistical visitor count implementation method. Share it with everyone for your reference, the details are as follows:

Without further ado, let’s start with the code:

Controller file:

/application/controllers/hello.php is as follows:

<&#63;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&#63;$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);
  }
}

Copy after login

View file:

/application/views/test_views.php is as follows:

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

Copy after login

The running results are as shown below:

Readers who are interested in more content related to the CodeIgniter framework can check out the special topic on this site: "Introduction to codeigniter tutorial"

I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.

Articles you may be interested in:

  • 2 Examples of how to write a Codeigniter file batch upload controller
  • PHP implements a shopping cart class that imitates CodeIgniter
  • Codeigniter's method of implementing get paging
  • Codeigniter's dom class usage example
  • CodeIgniter's method of using smtp service to send html emails
  • Configuring the codeigniter framework method under Nginx
  • Codeigniter's method of detecting form post data
  • Codeigniter's method of verifying IP address
  • Codeigniter controller controller inheritance problem example analysis

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1093706.htmlTechArticleCI (CodeIgniter) simple statistical access method original, cicodeigniter This article tells the example of CI (CodeIgniter) simple statistical access Number of people implementation method. Sharing it with everyone for your reference,...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template