本文實(shí)例講述了thinkPHP5框架設(shè)置404、403等http狀態(tài)頁面的方法。分享給大家供大家參考,具體如下:
要做到這一點(diǎn),首先要在你的配置文件將調(diào)試模式關(guān)閉(在開發(fā)階段要打開):
'app_debug' => false,
然后在配置文件 config.php 中配置404等頁面的模板路徑(APP_PATH指的是application路徑):
'http_exception_template' => [ // 定義404錯(cuò)誤的重定向頁面地址 404 => APP_PATH.'404.html', // 還可以定義其它的HTTP status 401 => APP_PATH.'401.html', 403 => APP_PATH.'404.html', ],
404頁面位于 application 目錄下,404.html部分代碼如下:
img src="__INDEX__/img/404.png" width="818" height="595" style="display: block;margin: 0 auto;"> div class="" style="font-size: 36px;margin: 0 auto;text-align: center;color: #323232;"> 您查找的頁面不存在,還有 span id="dd" style="color:darkorange;font-weight: bold;">6/span> 秒,頁面將自動(dòng)跳轉(zhuǎn)首頁... /div> !--倒計(jì)時(shí)--> script type="text/javascript"> function run(){ var s = document.getElementById("dd"); if(s.innerHTML == 0){ window.location.href='/'; return false; } s.innerHTML = s.innerHTML * 1 - 1; } window.setInterval("run();", 1000); /script>
測(cè)試 controller
if (Request::instance()->isAjax()) { $data = input(); $info = []; $where = ''; switch ($data['msg']) { case '驗(yàn)證碼': $info = [ 'y' => '輸入正確', 'n' => '輸入錯(cuò)誤', ]; $where = session::get('admin_login_session') == md5($data['param']);break; } if ($where) { echo '{"info":"' . $data['msg'] . $info ['y'] . '","status":"y"}';//注意ValidForm返回格式(json) } else { echo '{"info":"' . $data['msg'] . $info ['n'] . '","status":"n"}';//注意ValidForm返回格式(json) } }else{ throw new \think\exception\HttpException(403, '~~~非法請(qǐng)求~~~'); }
404效果如下圖:
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
標(biāo)簽:巴中 泰州 梅州 成都 威海 林芝 張家口 山東
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《thinkPHP5框架設(shè)置404、403等http狀態(tài)頁面的方法》,本文關(guān)鍵詞 thinkPHP5,框架,設(shè)置,404,403,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。