This article mainly introduces the thinkPHP5 framework settings 404, 403 HTTP Status page method, combined with the example form analysis of the THINKPHP5 Framework settings 404 page related configuration, view display page and controller call related operation skills, the need for friends can refer to the next
This example describes the THINKPHP5 framework for setting HTTP status pages 404, 403, and so on. Share to everyone for your reference, as follows:
To do this, first turn the debug mode off in your profile (open during development phase):
' App_debug ' = False,
Then configure the template path for page 404 in configuration file config.php (App_path refers to the application path):
' http_exception_template ' = [ //define 404 Error redirect page address 404 = app_path. ' 404.html ', //can also define other HTTP Status 401 = app_path. ' 401.html ', 403 = app_path. ' 404.html ', ],
404 page is located in the application directory, the 404.html section code is as follows:
<p class= "" style= "font-size:36px;margin:0 auto;text-align:center;color: #323232;" > The page you are looking for does not exist, and there is <span id= "dd" style= "color:darkorange;font-weight:bold;" >6</span> seconds, the page will automatically jump home ...</p><!--countdown--><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 ();",;</script>
Test controller
if (Request::instance ()->isajax ()) { $data = input (); $info = []; $where = "; Switch ($data [' msg ']) {case ' verification code ': $info = [ ' y ' = ' = ' input correct ', ' n ' = ' input error ', ]; $where = Session::get (' admin_login_session ') = = MD5 ($data [' param ']); if ($where) { echo ' {' info ': '. $data [' msg ']. $info [' Y ']. ' "," status ":" Y "} ';//note validform return Format (JSON)} else { echo ' {" info ":" '. $data [' msg ']. $info [' n ']. ' "," status ":" N "} ';//note validform return format (JSON)}}else{throw new \think\exception\httpexception (403, ' ~ ~ ~ ' Illegal Request ~ ~ ~ ');}
404 effects such as:
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!