Jump to content

Click Counter


lukep11a

Recommended Posts

Ok, I'm not sure if this is even possible but I will try and explain what I want to do and then maybe someone will be able to point me in the right direction. Say I have a link to an external site like google for example, when that link is clicked the target (google in this case) will open in a new window and the page on my site remains the same, is it possible to insert data into a table in my database at the same time when the link was clicked like an id value for the link, effectively creating a count, which can be displayed somewhere on the page? I really hope that makes sense, any help would be much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/253267-click-counter/
Share on other sites

Yes, but only with Javascript. Here's a quick (untested) script with jQuery:

$(document).ready(function(){
$('a.track').click(function(e){
	e.preventDefault;

	$.post('track.php?url=' + $(this).attr('href'));

	window.location = $(this).href;
});
});

 

Any anchor tags with the "track" class will trigger this event, which will send the HREF to a PHP script which will then interpret the $_GET variable and log it in a database.

Link to comment
https://forums.phpfreaks.com/topic/253267-click-counter/#findComment-1298291
Share on other sites

Yes, it's possible. Without JS. But you have to create a "special links". It might contain a link to a special script at your site and external link as a GET parameter for it. For example "count_links.php?http://www.google.com". This script count_links.php have to get a parameter, insert any information into DB and then route user to http://www.google.com.

 

I think it's the task that you asked.

Link to comment
https://forums.phpfreaks.com/topic/253267-click-counter/#findComment-1298887
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.