2012-07-12 37 views
1

後,我想執行以下的PHP(我使用5.2版本)格式的日期是:檢查今天,如果服務器時間是下午3:00 EST

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)?

在此先感謝您的幫助!

回答

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? 
} 
+0

此代碼實際上是一個驗證檢查,它存在於一個更大的PHP文件中。這就是說,雖然這設置了時區並檢查了時間......我怎麼才能確保只有當用戶選擇與今天的日期相同的日期時才發生此次檢查? – tmparisi 2012-07-12 17:11:50

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.'; 
    } 
} 
相關問題