RyanSF07 Posted June 24, 2009 Share Posted June 24, 2009 Hi Guys, I've been looking for a tutorial on how to write a script to count how many times a link has been clicked.. without having to redirect or modify the actual url. Seems like AJAX + PHP is the best way to do it. Any examples you've seen that you could suggest here? Thanks in advance ~ Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/ Share on other sites More sharing options...
.josh Posted June 24, 2009 Share Posted June 24, 2009 is the url itself never going to change? put a counting script on the target page. Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862376 Share on other sites More sharing options...
MadTechie Posted June 24, 2009 Share Posted June 24, 2009 You could use MySQL or a flatfile.. this really isn't the place to request "where can I find XYZ", When you say a link as been clicked, do you mean a link TO your site or a link ON your site, also how are the links being generated, also why not have a redirect or something added to the URL.. Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862377 Share on other sites More sharing options...
RyanSF07 Posted June 24, 2009 Author Share Posted June 24, 2009 thank you -- I realize not the place for posting this kind of help and won't keep this thread goings. Was just wondering if you knew of a good tutorial for developing one -- a tutorial that's not from 2005 I'd like to track clicks of links on the site to external urls. I'll keep looking ~ Cheers, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862384 Share on other sites More sharing options...
.josh Posted June 24, 2009 Share Posted June 24, 2009 In that case, the only way you are going to be able to do that is with javascript. The easiest way to implement that is by putting something in the link's onclick. Is there a reason why this isn't an option? If it is really not an option, you could setup an event listener to capture it on page exit, but that's still a javascript thing. Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862386 Share on other sites More sharing options...
MadTechie Posted June 24, 2009 Share Posted June 24, 2009 As for a quick simple php solution you could create the links like this <a href="http://www.mydomain.com/redirect.php?link=http://blar.com">http://www.blar.com</a> <?php //write log to text file or SQL header(Location: $_GET['link']); ?> Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862387 Share on other sites More sharing options...
.josh Posted June 24, 2009 Share Posted June 24, 2009 Also just thought I'd throw this out there... is there a specific way you were wanting to track this? Like, does this data need to be in your own system? Because you can setup a free google analytics account at http://www.google.com/analytics/ throw the global, generic tracking code on the bottom of your page(s), and it will automatically track all kinds of stuff for you, including exit link clicks (in other words, it already does what I mentioned in the previous post, as far as event listeners) Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862388 Share on other sites More sharing options...
.josh Posted June 24, 2009 Share Posted June 24, 2009 As for a quick simple php solution you could create the links like this <a href="http://www.mydomain.com/redirect.php?link=http://blar.com">http://www.blar.com</a> <?php //write log to text file or SQL header(Location: $_GET['link']); ?> He did say he didn't want to modify the url :\ Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862389 Share on other sites More sharing options...
MadTechie Posted June 24, 2009 Share Posted June 24, 2009 I know, I asked why, but didn't get a reply, so I thought I'll give a dirty example! Quote Link to comment https://forums.phpfreaks.com/topic/163446-solved-code-to-count-how-many-times-a-link-has-been-clicked-suggestions/#findComment-862394 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.