Reputation: 342
I am trying to make a counter for unique visitors in CodeIgniter using IP and session but this does not seem to work properly for me and I want to do it using cookies. So, I have written this function in my Controller -
function counter()
{
$this->load->helper('cookie');
$visitor = $this->input->cookie(urldecode(), FALSE);
$ipadrs = $this->input->ip_address();
if ($visitor == false)
{
$cookie = array(
"name" => urldecode(),
"value" => "$ipadrs",
"expire" => time() + 7200,
"secure" => false);
$this->input->set_cookie($cookie);
$this->news->update_counter(urldecode());
}
}
But this is not working, I have the update_counter function in my model.
I think I'm missing out on something very basic, any solutions for this?
Upvotes: 1
Views: 3868
Reputation: 1
function counter()
{
$this->load->helper('cookie');
$visitor = $this->input->cookie(urldecode(), FALSE);
$ipadrs = $this->input->ip_address();
if ($visitor == false)
{
$cookie = array(
"name" => urldecode(),
"value" => "$ipadrs",
"expire" => 7200,
"secure" => false);
$this->input->set_cookie($cookie);
$this->news->update_counter(urldecode());
}
}
Upvotes: 0
Reputation: 99
cookie is not working count unique visitors,
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values. cookie is not server side so not count you unique user.
http://coursesweb.net/php-mysql/register-show-online-users-visitors_t
Here is a nice tutorial ,is what you need.
Upvotes: 1