lukep11a Posted December 15, 2011 Share Posted December 15, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/253267-click-counter/ Share on other sites More sharing options...
scootstah Posted December 15, 2011 Share Posted December 15, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253267-click-counter/#findComment-1298291 Share on other sites More sharing options...
lukep11a Posted December 17, 2011 Author Share Posted December 17, 2011 But would that work if I had multiple links on the same page and they would all want to be counted individually? Quote Link to comment https://forums.phpfreaks.com/topic/253267-click-counter/#findComment-1298821 Share on other sites More sharing options...
SergeiSS Posted December 17, 2011 Share Posted December 17, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253267-click-counter/#findComment-1298887 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.