Last active
July 24, 2020 08:21
-
-
Save reactmore/cd3dde971fafb54989d8f38a0ce5bca7 to your computer and use it in GitHub Desktop.
Libraries Visitor Codeigniter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class visitor | |
{ | |
protected $CI; | |
public function __construct() | |
{ | |
$this->CI =& get_instance(); | |
} | |
// visitor | |
public function counter($address_visitor) | |
{ | |
date_default_timezone_set('Asia/Jakarta'); | |
if($this->CI->uri->segment(1) == "admin" || $this->CI->uri->segment(1) == "assets") { | |
}else{ | |
if ($this->CI->agent->is_browser()) | |
{ | |
$agent = $this->CI->agent->browser(); | |
} | |
elseif ($this->CI->agent->is_robot()) | |
{ | |
$agent = $this->CI->agent->robot(); | |
} | |
elseif ($this->CI->agent->is_mobile()) | |
{ | |
$agent = $this->CI->agent->mobile(); | |
} | |
else | |
{ | |
$agent = 'Unidentified User Agent'; | |
} | |
$visitor_data = array( 'url' => $address_visitor, | |
'ip_address' => $this->CI->input->ip_address(), | |
'user_agents' => $agent, | |
'date' => date('Y-m-d'), | |
'time' => date('Y-m-d H:i:s') | |
); | |
$this->CI->visitor_model->tambah($visitor_data); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class visitor_model extends CI_Model { | |
public function __construct() { | |
parent::__construct(); | |
date_default_timezone_set('Asia/Jakarta'); | |
} | |
// add | |
public function tambah($visitor_data) { | |
$this->db->insert('visitor', $visitor_data); | |
} | |
// Total visitor Website on Dashboard | |
public function visit_dash() { | |
$now = date('Y'); | |
$this->db->select('date, COUNT(*) AS total'); | |
$this->db->from('visitor'); | |
$this->db->group_by('date'); | |
$this->db->order_by('date', 'desc'); | |
$this->db->where('SUBSTR(date,1,4)', $now); | |
$this->db->limit(14); | |
$query = $this->db->get(); | |
return $query->result_array(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Welcome extends CI_Controller { | |
public function __construct() { | |
parent::__construct(); | |
// Load visitor | |
$allsite = current_url(); | |
$address_visitor = str_replace('index.php/', '', $allsite); | |
$this->visitor->counter($address_visitor); | |
} | |
public function index() | |
{ | |
$this->load->view('welcome_message'); | |
} | |
public function contoh() | |
{ | |
$this->load->view('welcome_message'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Welcome extends CI_Controller { | |
public function __construct() { | |
parent::__construct(); | |
// Load visitor | |
$allsite = current_url(); | |
$address_visitor = str_replace('index.php/', '', $allsite); | |
$this->visitor->counter($address_visitor); | |
} | |
public function index() | |
{ | |
$this->load->view('welcome_message'); | |
} | |
public function contoh() | |
{ | |
$list = $this->visitor_model->visit_Dash(); | |
$visit = []; | |
foreach($list as $row) { | |
$visit[] = ['date' => date('d F',strtotime($row['date'])), 'count' =>$row['total']]; | |
} | |
$data['visitor'] = json_encode($visit); | |
$this->load->view('charts', $data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment