开发者

Limit user to enter a competition 5 times every 24 hours?

I have built a Facebook app for a client, this app allows the user to enter their details and guess a figure to be entered into a competition. The app is run via an iframe.

Is there any possible way of only letting the user submit the form 5 times maximum within 24开发者_开发知识库 hours (preferably by facebook profile or IP address), then echo an error if they try to enter a 6th time. I have a php script that gathers the data and exports it to a csv file.

PHP form code:

<?php
if($_POST['formSubmit'] == "Submit")
{
    $errorMessage = "";

  if(empty($_POST['formName']))
  {
    $errorMessage .= "<li>You forgot to enter your name.</li>";
  }
  if(empty($_POST['formTown']))
  {
    $errorMessage .= "<li>You forgot to enter your town.</li>";
  }
  if(empty($_POST['formEmail']))
  {
    $errorMessage .= "<li>You forgot to enter your email.</li>";
  }

    $varName = $_POST['formName'];
    $varTown = $_POST['formTown'];
    $varAge = $_POST['formAge'];
    $varEmail = $_POST['formEmail'];

    $varOne = $_POST['hidden-one'];
    $varTwo = $_POST['hidden-two'];
    $varThree = $_POST['hidden-three'];
    $varFour = $_POST['hidden-four'];
    $varFive = $_POST['hidden-five'];

    if(empty($errorMessage)) 
    {
        $fs = fopen("mydata.csv","a");
        fwrite($fs,"\n" . $varName . ", " . $varTown . ", " . $varAge . ", " . $varEmail . ", " . $varOne . $varTwo . $varThree . $varFour . $varFive);
        fclose($fs);

        header("Location: thankyou.php");
        exit;
    }
}
?>


The obvious solution is to log form submits to a database. For each submit you log the time and an identifier for the user (IP address, Facebook account, etc). This data can be used to check how many times the user submitted the form in the last 24 hours. If this is more than X times, you do not store the data and inform the user.

But this solution assumes you have access to a database.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜