View Full Version : Link hit counter

01-03-2012, 09:21 PM
I have the following codes and it seems to work well but when exiting the site and re-entering it resets the values to 0 again.
I am not sure how to proceed with this, been considering cookies but what if the user clears there cookies, I then looked at PHP but not understanding that to well at this stage.
This was posted on the Javascript forum and they refered me here.


// Function to count clicks on links
var clicks1 = 0;
var clicks2 = 0;
var clicks3 = 0;
var clicks4 = 0;

function link1(){
document.getElementById('clicked1').value = ++clicks1;
function link2(){
document.getElementById('clicked2').value = ++clicks2;
function link3(){
document.getElementById('clicked3').value = ++clicks3;
function link4(){
document.getElementById('clicked4').value = ++clicks4;

HTML Code:

<tr valign="middle" align="center"><td colspan="1"><a target="_blank" href="http://mistiquestormelectronics.webs.com/" onclick="link1()"><img src="site_graphics/reinet.jpg" alt="Mistique Storm" width="120" height="90" /></a></td>
<td colspan="2" align="left"><p>For all your Electronic equipment needs.</p></td>
<td colspan="1" width="8%"><input id="clicked1" style="color: #000000; font-weight:bold; border-style: none; font-family: arial; background-color: #00FF00; text-align: center;" readonly="readonly" size="10" onfocus="this.blur();" value="0" ></td></tr>

Javascript forum advised me to use serverside cookie PHP or ASP dont know either but done some PHP(minimal), Please help.

The link on what I want to do is at:
I want it to show all users count that clicked the link and no unique users, also preferably with no mysql.

01-03-2012, 10:50 PM
Their site doesn't save the clicks either, so why would you want it like theirs?

You want the clicks saved permanently for every user?
And if that user comes back in 4 days, they see the same clicks as before?

The problem with IP is that it's not always the same.
Each time you connect with an ISP, it may give you a slightly different IP address.

Cookies might be more reliable, but people can erase them.

The only SURE way to do it is to require the user to log-in.
And then, you'll be using MySQL. But that's the very best way.
And it doesn't matter what computer the user is on ... when they
log-in, the clicks are counted and stay counted.

Other than a user log-in with password, you have no way to reliably monitor clicks.

01-04-2012, 06:16 AM
Sorry the page I gave as an example is the actual site I am working on, that is why it does not save. This website was a Javascript assignment and now I am fine tuning certain aspects but am totally new to PHP and never worked with MySql.
What would be my starting point?