开发者

Do THIS: only if between this timeframe

what I am trying to do with PHP is something I am sure is simple but cannot figure it out. What I need help with is this:

  • We have a Live Chat feature on our website that is turned 开发者_如何学JAVAon & off manually each day between 9am-6pm

  • What I would like is to be able to have the chat turned on & off based on the time. If the time is between 9am-6pm I would like the chat to be turned on. However, if the current time is not between that timeframe, I would like the Live Chat to be turned off.

All I need help with is the time functionality part. I just do not know how to put together the correct functions/if/else statements. Any help is greatly appreciated.


$c_time = mktime();
$open = strtotime('Today 8am');
$close = strtotime('Today 5pm');

if ($c_time > $open && $c_time < $close) {
    echo 'Chat open.';
} else {
    echo 'Chat closed.';
}

Demo: http://codepad.org/2QXXF8Lo (Remember this server may be in another timezone.)

I suppose technically all you need is:

$open = strtotime('8am');
$close = strtotime('5pm');

http://codepad.org/e0xjCuji

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜