How to set HTTP status pages such as 404 and 403 on the THINKPHP5 framework

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.