magebash Posted January 26, 2008 Share Posted January 26, 2008 I need help on making a click counter. It just needs to be able to count each time a person clicks on a link and put it in my database. If you can help please post here. Thanks. Link to comment https://forums.phpfreaks.com/topic/87851-how-to-make-a-click-counter/ Share on other sites More sharing options...
irvieto Posted January 26, 2008 Share Posted January 26, 2008 There are a few ways to make a click counter. An Easy way is to keep the "counter value" inside a file. So, everytime an user clicks on link like <a href="count_my_click.php">Click here<a> the php script will open the file, take its value into a variable, increase it and save it into the file again. When the work is done, you set a new header and continue to the wanted url. /* **** Content of count_my_click.php */ $file_handler = fopen("click.txt","w+"); /* bla,bla... get file data, increase it, bla bla.*/ fclose($file_handler); ### The job is done!! counter increased :-) header("Location:another_web.html"); Link to comment https://forums.phpfreaks.com/topic/87851-how-to-make-a-click-counter/#findComment-449496 Share on other sites More sharing options...
marcus Posted January 26, 2008 Share Posted January 26, 2008 Silly he wanted it to update his database. <?php $sql = "UPDATE `users` SET `clicks`=`clicks`+1 WHERE `uid`='".$_SESSION['uid']."'"; $res = mysql_query($sql) or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/87851-how-to-make-a-click-counter/#findComment-449500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.