我想製作一個限制用戶在工作時間後登錄的代碼: 用戶只應該從8:00登錄到4:35: Bellow是我嘗試過的代碼,我設法讓兩個條件工作,但第三個條件不工作:任何幫助將是非常讚賞:如何讓用戶只能在工作時間登錄?
<?php
# function to get right time of the targeted city
date_default_timezone_set('Africa/Johannesburg');
function time_diff_conv($start, $s)
{
$string="";
$t = array(//suffixes
'd' => 86400,
'h' => 3600,
'm' => 60,
);
$s = abs($s - $start);
foreach($t as $key => &$val) {
$$key = floor($s/$val);
$s -= ($$key*$val);
$string .= ($$key==0) ? '' : $$key . "$key ";
}
return $string . $s. 's';
}
$date = date('h:i');
echo $date;
/*Start time for work*/
$workStart = strtotime("08:00");//am
/*Stop time for work*/
$workStop = strtotime("04:35");//pm
/*This is the current time*/
$currentTime = strtotime($date);
//$fromSatrtToEnd = $workStart->diff($workStop);
/*This Condition works*/
if($currentTime >=$workStart){
echo "Start Working";
/*This Condition also works*/
} else if($currentTime < $workStart){
echo "You too early at work";
}
/*This Condition does not works*/
else if($currentTime < $workStop){
echo "Its after work";
}
?>
我希望我可以upvote你:你做了一個偉大的工作,現在我的代碼現在工作reming這是與腰部代碼集成 –