1

我想在 PHP 中执行以下操作(我使用的是 5.2 版):

IF form_date = current_date AND server_time >= 3:00pm EST
GIVE ERROR

form_date:用户输入表单的日期。

current_date:今天的日期。

server_time:主机服务器提供的当前时间。

这是我到目前为止所拥有的:

//time validation
if (date("Gi") > '1500') {
    $process_result['custom_error'] = "You not able to register after 3 PM";
}

我不确定如何完成这件事,因为 PHP 根本不是我的事。此外,服务器是否只返回它设置的任何时区,还是可以将其更改为特定时区,例如东部标准 (EST)?

提前感谢你的帮助!

4

2 回答 2

1

要设置默认时区,请使用: http ://www.php.net/manual/en/function.date-default-timezone-set.php

date_default_timezone_set('America/New_York');

为了完成代码,我将重定向到另一个页面,该页面告诉用户它完全失败了:

<?php
date_default_timezone_set('America/New_York');
if (date("Gi") > '1500') {
    header("Location: http://example.com/failed_registration.php");
}else{
 //how are you going to register them?
}
于 2012-07-12T17:00:30.867 回答
0

我最终使用了以下效果很好。

//time validation for day-of reservations
date_default_timezone_set('America/New_York');
if (date("Gi") >= '1500'){
    if (date("m.d.y") == date("m.d.y",strtotime($table_data['element_' . $date_element_id]))){
    $error_elements[$date_element_id] = 'You are not able to make an online reservation for today, after 3:00pm EST.  Please call us at xxx-xxx-xxxx to make your reservation.';
    }
} 
于 2012-07-12T19:50:09.513 回答