How to count link clicks?

I’m sorry to say that you won’t get around using JavaScript for this.
PHP is a server-side language that spits out a load of HTML to be served up by the browser, whereas JavaScript is a client-side language which can dynamically influence the way your user interacts with the page.

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.


Edit:
Just thinking out loud, you could code the link like this:

<a href="linkcounter.php?www.sitepoint.com">Sitepoint</a>

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.

1 Like