I'd like to put a link on a webpage and show a count of the number of clicks that link has received.
The link might look like this:
How do I do that?
I'm slowly teaching myself a little PHP, so I'm not looking for the full code. Some pointers on how to do it would be great?
Would the link be to an external site or a separate page with your site?
Thanks Pullo, it would link to an external site. I won't be able to add any code to the site it links to.
When the link is clicked, this event listener could then fire off a quick AJAX request to a PHP script that increments your link click count by one (either in a txt file or database).
Following this, you could then direct your visitor to their intended goal.
I think there are 2 solutions to it.
You can save the click count in database and increment it with a small request when the link is clicked and before redirecting it to the external site.
Upload a txt file on server and update it with the count, when the link is clicked.
Thanks again, if I can figure out how to store the number of clicks in a variable, I'm comfortable with outputting that number on a HTML page.
Thanks Jimmy. With no. 2.
"Upload a txt file on server and update it with the count"
I know how to do that.
"when the link is clicked"
How would my script know when the link is clicked? To put it another way, if I put the code to update the count in a text file inside an if statement. What condition should I use for the if statement?
Assuming the link gets a lot of clicks, would using a text file like that be an efficient way to do it, or would it slow down my site?
Nah, probably not.
If you get to the point where you have enough visitors to slow your site by clicking on this link, whether to use a text file or not will be the least of your worries.
Just thinking out loud, you could code the link like this:
And have linkcounter.php update the count, grab your destination from the query string, then set the header to redirect you to your original goal.
If you want something that's relatively easy to set up and monitors clicks and downloads - try 'Click Counter'
I've been using it to count downloads for a few months and it appears to be reliable. A free version is available.
Yes, I will also recommend the same.
Thanks, will try to do it that way.
Thanks for the suggestion, looks like it might be an option.
There are two ways to do this one save the click count in database and increment it with a small request when the link is clicked and before redirecting it to the external site and second is that Upload a txt file on server and update it with the count, when the link is clicked.
This topic is now closed. New replies are no longer allowed.