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.
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:
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.
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.