title: Creating hit Counter
body: <p>I am trying to create a hit counter for my website and I have developed the following code for it. I have included the following code only in Codeigniter's main controller for my home page.</p>
  
  <p>At first I thought the code was working fine but I just found that if I don't keep on browsing the pages then again go to the home page it doesn't update the data. I mean for example: If I go to my homepage for the first time then it updates the data, but after 10 seconds if I refresh the page it does't update the data. But if I keep refreshing it for 10 seconds then it works.</p>
  
  <p>So could you please tell me how to get it update the data without having to keep on browsing the pages or refreshing the home page?</p>
  
  <p>Thanks :)</p>
  
  <pre><code>function __construct() {
  
      parent::__construct();
  
      // Visitor Counter
      if (!$this-&gt;session-&gt;userdata('timeout')) {
  
          $out = time() + 10; // I will change it to $out = time() + 60*60; later 
          $this-&gt;session-&gt;set_userdata('timeout', $out);
          mysql_query("UPDATE cane_visitor_counter SET visitor_stat = visitor_stat+1 
                WHERE id = '1'");
      } else {
          $timeout_time = $this-&gt;session-&gt;userdata('timeout');
          if (time() &gt; $timeout_time) {
  
              $this-&gt;session-&gt;set_userdata(array('timeout' =&gt; ''));
              $this-&gt;session-&gt;sess_destroy();
          }
      }
  }
  </code></pre>
  
  <h2>edit</h2>
  
  <p>What I am trying to achieve is when an user visits the webpage for the first time, I want to update my database. Within 10 seconds (for example purpose), if the visitor again visits the home page, the database will not be updated. But after 10 seconds if he again visits the home page, I want to update my database. </p>
  
  <p>Thanks :) </p>