开发者

Creating a Form for a Competition that can only be submitted once per user

开发者 https://www.devze.com 2023-03-20 03:25 出处:网络
I\'ve create a facebook App that once a user has liked a page they are sent to a reveal page which contains an entry form for a competition,

I've create a facebook App that once a user has liked a page they are sent to a reveal page which contains an entry form for a competition,

Is there a开发者_JAVA技巧 method to make it so the user can only submit the form once?


Is there a method to make it so the user can only submit the form once?

I think you first need to authenticate user(Facebook does that for you?). I assume you are using something like below:

<?php 

     $app_id = "YOUR_APP_ID";

     $canvas_page = "YOUR_CANVAS_PAGE_URL";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page);

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
            echo ("Welcome User: " . $data["user_id"]);
     } 
 ?>

Then could authorize the user($data["user_id"]) if it is a new user proceed. If not then halt. You can keep track of the users by storing $data["user_id"] in your database.


That's a pretty vague question.

If you really just want to prevent them from submitting the form multiple times (by clicking more than once on the submit button), you can use a simple bit of Javascript to disable the button when it's clicked on (or the form is submitted another way, such as by hitting the enter/return key).

However, I kind of think that rather than preventing them from submitting the form multiple times, you really just want to ignore all but the first submit. You'll need a way to uniquely identify that user/machine - how you do that really depends on what information you can provide yourself with.

One possible solution is using a cookie with a unique value that lasts for a certain amount of time (a day, week, month or year - pick whatever you feel is appropriate for your use; if the competition is only running for a week, you don't need a cookie that lasts for a year, for example).

When they submit the form the first time, track that an entry has come from the machine with the cookie containing that value, and ignore any subsequent entries that have that same cookie value.

Obviously this isn't completely secure - they could delete their cookies, or modify the value of this particular cookie, to enter again, but a lot of users won't do that. They'll also be able to enter multiple times if they use more than one web browser. If you have something else

0

精彩评论

暂无评论...
验证码 换一张
取 消