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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.