Welcome Guest, Not a member yet? Register   Sign In
hit counter
#2

[eluser]Pascal Kriete[/eluser]
So what you want is a simple page hit counter? Pretty simple really. All you need is a mechanism to avoid duplicates. It's easiest to just track ip addresses.

Code:
/* Hits table has an auto-incrementing id and an ip field */

// Grab client IP
$ip = $_SERVER['REMOTE_ADDR'];

// Check for previous visits
$query = $this->db->get_where('hits', array('ip' => $ip), 1, 0);
$query = $query->row_array();

if (count($query < 1) )
{
    // Never visited - add
    $this->db->insert('hits', array('ip' => $ip) );
}

To display the counter, simply count all rows:
Code:
echo $this->db->count_all('hits');

Welcome to CodeIgniter.


Messages In This Thread
hit counter - by El Forum - 05-08-2008, 04:09 AM
hit counter - by El Forum - 05-08-2008, 04:45 AM
hit counter - by El Forum - 05-08-2008, 04:52 AM
hit counter - by El Forum - 05-08-2008, 05:05 AM
hit counter - by El Forum - 05-09-2008, 03:28 AM
hit counter - by El Forum - 05-09-2008, 03:36 AM
hit counter - by El Forum - 05-09-2008, 08:49 PM
hit counter - by El Forum - 07-03-2008, 02:16 AM



Theme © iAndrew 2016 - Forum software by © MyBB