Limit to one click per person

Asked

Viewed 74 times

2

I want to limit the click of a button to 1 click per computer. It is possible?

Code so far:

<html>
    <body>
    <br><br>
    <a style="color: grey; background-color: #fff; font-family: Arial; text-decoration: none; padding: 25px 50px; border-radius: 3px;" href="http://hugovales.esy.es/likeme/download_arquivo.php">I Like!</a>
    <br><br><br><a style="color: #fff; font-family: Arial;"><? include "contador_arquivo.txt"; ?> People Enjoy it</a>
    </body>
</html>
  • I know you said "by computer", but it would not be the case to be "per user?". In this case it would be enough to create a registration/ login and ready***.

1 answer

2

Opa use esse javascript:

var createCookie = function(name, value, days) {
    var expires;
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    else {
        expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) {
                c_end = document.cookie.length;
            }
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

Provided by: Soen

After that you can create a function at the click of the link:

<a style="color: grey; background-color: #fff; font-family: Arial; text-decoration: none; padding: 25px 50px; border-radius: 3px;" href="http://hugovales.esy.es/likeme/download_arquivo.php" onclick=" return check()">I Like!</a>

then create a function to validate:

function check(){
    check = getCookie('isclique');
    if(check){
       return false;
    }
    createCookie('isclique','true',100);
}

Something like that. I was in a hurry. But this validation is not 100%, the "only" way 100% still gives to cheat but is safer than this, would validate in the backend.

  • 1

    As @Guerra mentioned, this validation is not 100% because it is limited to navegador, if the user changes browser he will be able to click again.

  • 2

    An observation, here only works if you put onclick="return check()" instead of onclick="check()", that really makes more sense.

  • I couldn’t. On each page I put each of the codes?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.