Where to put my hit counter code in my php class of codeigniter?
Why not implement a PHP native session ? You could also your CI's session for this implementation.
<?phpsession_start(); //<--- Add hereclass Welcome extends CI_Controller{ function __construct() { if(!isset($_SESSION['visited'])) { hit_counter(); // works perfectly fine... $_SESSION['visited'] = true; //<--- Sets here the first time. } }