I'm building a simple date verification script and I just stumbled onto a big problem.
$correct_date = FALSE;
if ($legal_month == $month_wozero || $legal_month == $month_wzero) {
if ($legal_day == $day_wzero || $legal_day == $day_wozero) {
if ($legal_year == $year)
$correct_date = TRUE;
}
}
$legal_day, $legal_month, $legal_year = user input
$day_wozero/wzero, $month_wozero/wzero, $year = server time
The user needs to enter the date in which they placed the order. But clearly, this is never going to work with the way I’ve setup my script. The location of the business is -2 hours from the server. But that doesn't matter since someone can place the order anywhere with in the United States. So if they are in New York, it could be the next day, and the business being in LA, the dates would differ. Also It could be the last day of the month and the month in New York would differ as well from LA.
The only way around this is in my head is to build an entire if/else nested set of rules to adjust for time and month difference at specific times. But I'm almost sure there has to be another way around this that I'm not aware of.
Any suggestions?
I would opt to add a timezone dropdown and attempt to select the correct one for them using JS so that you can sleep easy knowing that it is being provided to you from the client-side.
Upon receiving the data on your server you should either use this information to convert the user-date to the server's timezone and compare them or create a a server-date value which is in the user-supplied timezone and check against that.
Example
// We'll want this for later
$server_timezone = date_default_timezone_get();
// Did the user supply a timezone and is it valid?
if(
$_POST['user_supplied_timezone'] !== '' &&
date_default_timezone_set($_POST['user_supplied_timezone']) === TRUE
)
{
// This accepts yyyy/m/d or yyyy/mm/dd formats
if(
$_POST['user_year'] === date('Y') &&
($_POST['user_month'] === date('n') || $_POST['user_month'] === date('m')) &&
($_POST['user_day'] === date('j') || $_POST['user_day'] === date('d'))
)
{
// TRUE
}
}
// It is officially "later"
date_default_timezone_set($server_timezone);
How can I obtain the local time in jQuery?
You could always get the local time and debate on the date on the client slide and enter the current timezoned time in a hidden input type somewhere on the form.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With