我想制作一个限制用户在下班后登录的代码:用户只能在 8:00 到 4:35 之间登录:波纹管是我尝试过的代码,我设法使两个条件起作用,但第三个条件不起作用:任何帮助将不胜感激:
<?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";
}
?>