www.webdeveloper.com
Results 1 to 3 of 3

Thread: Image CLICK counter

  1. #1
    Join Date
    Dec 2011
    Posts
    29

    Question Image CLICK counter

    hello guys
    I have an Image on my page and I want to count how many times the image has been clicked on and show the number beside the image. Also I dont want the number to reset everytime the page is reloded.

    How can I do that
    Thank you for help

  2. #2
    Join Date
    Jul 2011
    Posts
    131
    You have to use AJAX for that purpose. And you also need to save your current counter somewhere on the server, for example in the database.
    Just send AJAX request only after clicking on the image and update the number of clicking.

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    A simple image counter can be made without Ajax like on this page (see the source). The imagecounter.php file remove, on each call, the javascript file imagecounter.js with the new value and reload it to display this one...

    Code:
    <?php
    // imagecounter.php file
    	header("Cache-Control: no-cache, must-revalidate");
    	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    	header("Content-Type:text/javascript;charset=utf-8");
    	$cnt=file_get_contents("imagecounter.js");
    	$nmb=preg_replace("`[^\d]+`",'',$cnt);
    	$nmb++;
    	$fch=fopen("imagecounter.js","w+");
    	$ncn='var count='.$nmb.';'.chr(13).chr(10);
    	$ncn.='document.getElementById("counter").innerHTML=count;';
    	// remove the js file   
    	fwrite($fch,$ncn);
    	// return the new script
    	echo $ncn;
    ?>
    A single difficulty, it would be advisable to preload the sound !

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles