kishankakadiya
kishankakadiya

Reputation: 85

How to calculate page views in Codeigniter and count by IP address?

Please explain steps how to calculate page views in codeigniter.

Is there any instruction on how to do this.

by using following method:

$this->input->ip_address();

How to Write $this->input->ip_address(); in Below Controller:

Controller Page

class About extends CI_Controller {
function __construct() {
        parent::__construct();
        $this->load->helper('array');
        $this->load->model('about_model');
        }

          public function index() {
            $data = array(
            'page_title' => 'About',
            'page_name' => 'site/aboutus/about',
            'about' => $this->about_model->list_all(),
            );
             $this->load->view('site/template', $data);
            }
}
?> 

Model Page:

class About_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function list_all() {
        return $this->db->get('about')->result_array();
    }
}

Upvotes: 1

Views: 2258

Answers (1)

Owais Aslam
Owais Aslam

Reputation: 1589

  1. $this->input->ip_address() to take the user's ip address in the controller
  2. In the database you save the ip, the time the user first visited the site and a counter
  3. Get the counter: $this->db->select_sum("counter")->get("views_table"); and process the result.

Upvotes: 3

Related Questions