Jump to content

Recommended Posts

Assume this project is to create an online lottery system.

 

Is there a way to limit the user entering the numbers after a certain time?

 

E.g. The Draw will be at 9.00PM 05 November 2010 - Submitting the numbers will expire after 8.00PM 05 November 2010. (so any user tries to submit numbers after 8.00PM 05 Nov 2010 will not be entered in to the MySQL db).

 

Any help is highly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/217545-expirevalidate-submissions-by-datetime/
Share on other sites

You need to determine the draw date/time in the code; then determining if the user is submitting their numbers too close to the draw is very simple. However, since I assume there are going to be multiple draws, you need to decide how you will determine the draw that the person is submitting numbers for. Are you only going to allow them to submit numbers for the next draw or can they submit numbers for any future draw?

 

Anyway, once you have decided on that logic here is how you can test if the submission is x minutes before the draw.

 

You can either get the draw date/time into logical values for hour, minute, second (or just use zero), month, day & year; then use mktime(). Or you can get the date/time of the draw in a string format and use strtotime();

 

$cutoffTime = 60; //Cutoff in minutes
$drawTime = mktime($drawHour, $drawMinute, 0, $drawMonth, $drawDay, $drawYear);

//Test if the timestamp (in seconds) for the drawtime minus the
//timestamp for NOW (i.e. the number of seconds from now until
//the draw) is less than the cutoff time in seconds.
if($drawTime-time() < $cutoffTime*60)
{
    //Submission is after the cutoff time
    // - add error handling
}
else
{
    //Submission on or before the cutoff time
    // - allow the submission
}

That was very helpful mjdamato!! Thanks.

 

Are you only going to allow them to submit numbers for the next draw or can they submit numbers for any future draw?

They can actually submit numbers for the next draw only.

 

Is this how to go about it?

$cutoffTime = 44640; //Cutoff set to one month
$drawTime = mktime($20, $5, 0, $12, $25, $2010); //8:05PM on 25/12/2010

if($drawTime-time() < $cutoffTime*60)
{
    $sentOk1 = "Expired!.";
    echo "sentExpired=" .$sentOk1;
}
else
{
$query = "INSERT INTO decdraw(name, phone, address, postal, email, number1, number2, number3, number4, number5, number6,) //up to number15, VALUES('$name','$phone','$address','$postal','$email','$number1','$number2','$number3')" // to $number15;
$result = mysql_query($query);

$sentOk2 = "Your numbers has been added to the database.";
echo "sentOk2=" .$sentOk2;
}

 

One more question, Can a MySQL handle a lot of entries? or isn't it wise to use MySQL to store the draw numbers + user info?

$cutoffTime = 44640; //Cutoff set to one month

So, you are saying that people must submit thier number at least one month prior to the draw? According to your first post I thought the cutoff time was going to be one hour. If you want the cutoff to be a month I would have taken a different approach since a month can be anywhere from 28 to 31 days. I'd probably use strtotime().

 

$drawTime = mktime($20, $5, 0, $12, $25, $2010); //8:05PM on 25/12/2010

Well, you shouldn't have variable names that begin with numbers, but assuming those variable names are just for illustrative purposes and they would hold the value that is the same as the names, that is correct.

 

And yes MySQL would be fine for holding "a lot" of records. It is a database, that's kind of what it's supposed to do. I'm not saying the code works though, you need to test it. Just set the draw time and the expiration so you have a 5 minute window to submit numbers. Ensure you can submit up until the cutoff and then get the expiration message afterward.

  • 2 weeks later...

Well, check the manual, that's what it is there for: http://php.net/manual/en/function.strtotime.php

 

If the cutoff time is 7 days before the draw time, here is one possible solution:

$drawTime = mktime($20, $5, 0, $12, $25, $2010); //8:05PM on 25/12/2010
if(strtotime('+7 days') > $drawTime)
{
  //Don't allow submission
}
else
{
  //Allow submission
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.