PHP出错界面详细说明,php出错详细说明
PHP出错界面详细说明,php出错详细说明
在web 上所有常见的错误之一就是无效的链接。一旦从其它站点上出现了无效的链接,你会重新安排你
的站点。人们会将他们喜欢的站点存成书签,如果在三个月后再次访问时,仅仅发现的是'404 Not Fount '
时,将不会给他们任务帮助,告诉他们如何从你的站点去查找原始的信息。让我们解决这个问题,或者至少
给你的用户一个友好的帮助,一旦他们遇到'a 404' 错误时,能够得到一些痕迹。你可以创建普通的页面来
报告在处理你的页面时所遇到的所有的错误。
PHP 与Apache一起可以很自由地让你创建自已的出错页面,但是需要重新进行配置,并且要编少量的代
码。先让我们学习配置部分。
Apache的ErrorDocument指示用来指出在出现错误时Apache应重定向到哪一个文档(或URI)。它允许你
为每一个你的用户可能遇到的错误代码指定一个资源。通过在你的服务器配置中增加一个ErrorDocument 404
/error.php指示。这个将在用户访问一个不存在的页面时,重定向到'error.php'中,下面我们就会写出
'error.php'页面。不要忘了重新启动Apache以使改动生效。
接着,我们写出一个简单的error.php:
你所请求的文件 (=$REDIRECT_URL?> ) 在这个服务器上不存在。
请查找你想要的文件从 前页。
现在试着读取一个在你服务器上不存在的页面,怎么样,你可以看到error.php了,它有着一个良好和
友好的消息,并且还有一个到前页的链接。
让我们把它扩展一下。正如你所见,我在error.php中使用了REDIRECT_URL变量。这个变量是Apache在
执行了一个ErrorDocument指示时所设置的,并且给出了一种可能来找到原始的资源。在这种情况下,Apache
还设置了一些别的变量,所有的变量可以在这里找到。使用这些变量可能创建一个很好的出错页面,用于给
用户一个不错与友好的出错页面,而代替Apache给出的缺省页面。
从PHP页面中输出错误
从一个PHP页面输出错误与模拟Apache对ErrorDocument指示所做的很象,你只要简单地将用户重定向,
通过使用query-string变量,而Apache则通常是设置在环境变量里面。这样就可以使用同一个出错页面来处
理各种错误。下面是一个例子:
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();
// 使用输出缓冲以便在这页中的任何地方输出错误
if(!condition) {
throw_error("the condition failed");
}
ob_end_flush();
// 页面处理完毕,刷新输出缓冲
?>
使用PHP4的输出缓冲特性对生成一般的出错报告功能也会有帮助。但是在你确认整个出错页面处理完毕
时,不要忘记刷新缓冲区,你可以在你的代码中的任可地方通过Header调用来进行重定向。
详细说明:http://php.662p.com/thread-333-1-1.html
a.php(注册页面)
b.php(处理页面,末尾是两种跳转方法)
代码在这儿(删去不必要的可以测试一下)
a.php

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
