Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    92
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Question Link hit counter

    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.

    Javascript

    Code:
    // 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:

    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:
    www.sayorkies.co.za/friends.html
    I want it to show all users count that clicked the link and no unique users, also preferably with no mysql.

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,386
    Thanks
    8
    Thanked 1,077 Times in 1,068 Posts
    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.

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    92
    Thanks
    38
    Thanked 0 Times in 0 Posts
    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?

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •