請教個關於限制時間段訪問網頁代碼

來源:互聯網
上載者:User
我網站現在的限制訪問時間段是24小時制,也就是可以從開始時間00:01到24:00結束,現在我想要從開始時間10:00到02:00結束就用不了,請問怎麼用代碼可以這樣限制時間訪問嗎?


回複討論(解決方案)

擷取目前時間,不是容許的時間段給出提示。。。

24小時制,開始時間10:00到02:00結束
這不就跨天了嗎?
所以你要分2段設定
00:00 到 02:00
10:00 到 24:00

24小時制,開始時間10:00到02:00結束
這不就跨天了嗎?
所以你要分2段設定
00:00 到 02:00
10:00 到 24:00
能發下代碼嗎?

你原來只有類似
date('H:i') >= $起始時間 and date('H:i') < 結束時間
這樣一條判別
加一條判別就是
date('H:i') >= $起始時間1 and date('H:i') < 結束時間1
or
date('H:i') >= $起始時間2 and date('H:i') < 結束時間2

你原來只有類似
date('H:i') >= $起始時間 and date('H:i') < 結束時間
這樣一條判別
加一條判別就是
date('H:i') >= $起始時間1 and date('H:i') < 結束時間1
or
date('H:i') >= $起始時間2 and date('H:i') < 結束時間2
這樣不起衝突嗎?

你原來只有類似
date('H:i') >= $起始時間 and date('H:i') < 結束時間
這樣一條判別
加一條判別就是
date('H:i') >= $起始時間1 and date('H:i') < 結束時間1
or
date('H:i') >= $起始時間2 and date('H:i') < 結束時間2
版主,麻煩給個完整的代碼。


沖什麼突?



你原來只有類似
date('H:i') >= $起始時間 and date('H:i') < 結束時間
這樣一條判別
加一條判別就是
date('H:i') >= $起始時間1 and date('H:i') < 結束時間1
or
date('H:i') >= $起始時間2 and date('H:i') < 結束時間2
這樣不起衝突嗎?


沖什麼突?




你原來只有類似
date('H:i') >= $起始時間 and date('H:i') < 結束時間
這樣一條判別
加一條判別就是
date('H:i') >= $起始時間1 and date('H:i') < 結束時間1
or
date('H:i') >= $起始時間2 and date('H:i') < 結束時間2
這樣不起衝突嗎?
版主,麻煩發個全部代碼好嗎?

自己不會寫?
那就把你原來的這部分貼出來
不然我給你寫了,你也弄不進去

自己不會寫?
那就把你原來的這部分貼出來
不然我給你寫了,你也弄不進去

//提示時間檢查$fromTime=strtotime(date('Y-m-d ',$this->time).$this->settings['cashFromTime'].':00');$toTime=strtotime(date('Y-m-d ',$this->time).$this->settings['cashToTime'].':00');if($this->time < $fromTime ||$this->time > $toTime ) throw new Exception("對不起,已過提現時間,請在合適的時間提交!
提現時間:".$this->settings['cashFromTime']." ~ ".$this->settings['cashToTime']);$this->beginTransaction();try{$this->freshSession();if($this->user['coinPassword']!=md5($para['coinpwd'])) throw new Exception('資金密碼不正確');unset($para['coinpwd']);if($this->user['coin']<$para['amount']) throw new Exception('你帳戶資金不足');


這是代碼

訪問的時候你用php調取目前時間判斷,如果是在允許時間內就繼續運行,否則打道回府!

訪問的時候你用php調取目前時間判斷,如果是在允許時間內就繼續運行,否則打道回府!

//提示時間檢查$fromTime=strtotime(date('Y-m-d ',$this->time).$this->settings['cashFromTime'].':00');$toTime=strtotime(date('Y-m-d ',$this->time).$this->settings['cashToTime'].':00');if($this->time < $fromTime ||$this->time > $toTime ) throw new Exception("對不起,已過提現時間,請在合適的時間提交!
提現時間:".$this->settings['cashFromTime']." ~ ".$this->settings['cashToTime']);$this->beginTransaction();try{$this->freshSession();if($this->user['coinPassword']!=md5($para['coinpwd'])) throw new Exception('資金密碼不正確');unset($para['coinpwd']);if($this->user['coin']<$para['amount']) throw new Exception('你帳戶資金不足');

目前是24小時制的,我需要的是跨天時間,比如08點到02點,上面是我的PHP代碼,請問怎麼改?

strtotime(date("Y-m-d"));//00:00strtotime(date("Y-m-d 02:00"));//02:00strtotime(date("Y-m-d 22:00"));//22:00strtotime(date("Y-m-d 24:00"));//24:00
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.