سؤال

I don't have access to run server-side code, so I can't do a PHP session for a registration form. I am going with a client cookie to ensure only one registration per person (per unique e-mail).

Following How do I set/unset cookie with jQuery? I thought I got the hang of it.

But it seems, even if I put in a new e-mail, it will always return alert("You've already registered");. Why is that?

enter image description here

        $("#submitBtn").click(function (event) {
            var subject = "Registration for Walk-a-thon",
                name = document.getElementById("name").value,
                email = document.getElementById("email").value,
                message = document.getElementById("message").value;     

            if (!$.cookie('client_email_cookie')) {                             
                $.cookie("client_email_cookie", email, { path: '/', expires : 10});
                log("Cookie: " + $.cookie("client_email_cookie"));
                var link = "mailto:Jun.Ma2@otis.com; Allison.Rocca@utc.com"
                         + "?cc=daniel.turcotte@carrier.utc.com"
                         + "&subject=" + escape(subject)
                         + "&body=" + escape(message)
                ;
                window.location.href = link;                    
            }
            else {
                alert("You've already registered");
            }
        });
هل كانت مفيدة؟

المحلول

if (!$.cookie('client_email_cookie')) only checks to see if the cookie exists, it doesn't check its value.

$.cookie('client_email_cookie') returns the value of the cookie (in your case email). Compare that value to the email that was entered to see if it has been registered.

Also, not to state the obvious, but this can be easily defeated anyway by the user simply deleting the cookie if they so desire, registering from a different browser or computer, using private browsing, etc...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top