PHP Error Interface Detailed description

Source: Internet
Author: User
Tags php error

One of the most common errors on the Web is the invalid link. Once an invalid link appears from another site, you will reschedule your
of the site. People will store their favorite sites in a book, if they visit again after three months, only to find that ' 404 Not fount '
, they will not be given the task help and tell them how to find the original information from your site. Let's solve this problem, or at least
Give your users a friendly help, and once they encounter a ' a 404 ' error, they can get some traces. You can create a normal page to
Reports all errors that are encountered while processing your page.

PHP is free to create your own error page with Apache, but it needs to be reconfigured and a small number of generations
Code. Let's learn the configuration section first.

Apache's errordocument indicates which document (or URI) Apache should redirect to when an error occurs. It allows you
Specify a resource for each error code that your users may encounter. By adding a errordocument 404 to Your server configuration
/error.php instructions. This will redirect to ' error.php ' when the user accesses a nonexistent page, and we'll write
' error.php ' page. Do not forget to restart Apache for the changes to take effect.

Next, we write a simple error.php:

The file you requested (<?= $REDIRECT _url?>) does not exist on this server.
Please find the file you want from <a href= "/" > front page </A>.

Now try to read a page that does not exist on your server, how, you can see error.php, it has a good and
Friendly message, and there is a link to the previous page.

Let's extend it a bit. As you can see, I used the Redirect_url variable in error.php. This variable is Apache in
A errordocument indicator is executed, and a possible way to find the original resource is provided. In this case, Apache
Also set some other variables, all of which can be found here. Using these variables may create a good error page for
User A nice and friendly error page instead of the default page given by Apache.

Output Error from PHP page
Output error from a PHP page is similar to simulating Apache's errordocument instructions, so you simply redirect the user
By using the query-string variable, Apache is usually set inside the environment variable. This allows you to use the same error page to place
All kinds of mistakes. Here is an example:



<?php

function Throw_error ($message) {
$error _page = "/err/error.php";

$error _url = $error _page;
$error _url. = "? redirect_error_notes= $message ";
$error _url. = "&redirect_url=". $GLOBALS ["Php_self"];
$error _url. = "&redirect_request_method= $REQUEST _method";
$error _url. = "&redirect_status=501";
Header ("status:501");
Header ("Location: $error _url");
Exit
}

Ob_start ();
Use output buffering to output errors anywhere on this page

if (!condition) {
Throw_error ("The condition Failed");
}

Ob_end_flush ();
Page processing complete, refresh output buffer
?>
Using the output buffering characteristics of the PHP4 is also helpful in generating general error reporting. But after you confirm that the entire error page has been processed,
, do not forget to flush the buffer, you can use the header to redirect in any place in your code.

Detailed Description: http://php.662p.com/thread-333-1-1.html

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.