Common causes and solutions for PHP blank pages

Source: Internet
Author: User
Tags include php file blank page
Resolution | Page

Writing PHP, there will inevitably be errors. In fact, errors are not difficult to solve, the most difficult to solve is the appearance of blank pages. Everyone think about it, if you write PHP errors, you can correct the error prompts, if PHP does not show you anything, it is not to let the writer trapped not to? Below, I will be writing PHP when I summed up on the PHP blank page solution and the cause. Of course, I write PHP is not very expert, so if there are errors, please do not hesitate to point out.

1, the action is not defined
Let's take a look at the following code:
The following is the program code
<?php
$action = $_get[' id '];
if ($action = = ")
$action = 1;
if ($action = = 1) {
Echo ("\ $action ' s value is 1");
else if ($action = = 2) {
Echo ("\ $action ' s value is 2");
}
?>

This code is very clear, that is, if the $action variable is empty, set it to 1, and then judge the value of the $action variable to make a different event. Of course, if $action is neither equal to 1 nor equal to 2, what does PHP do?? Nothing will be done, so there will be a blank page. Knowing the reason, the solution is easy. The solution to this problem is simply to add an else to the If module.

2. Grammatical errors
You may ask, if there is a grammatical error, the general will have the wrong hint, how can it be blank? Of course, this is only a few individual phenomena, in some home space (such as China's free Space Network), if you write PHP syntax errors, it will not have any hint. The solution is also very easy, before uploading the file in the local test, find the wrong code to correct.

3. Logic Error
This problem is the most difficult to exclude, on the surface, perhaps the code is legal, is formal, can be run but not expected. Why, then? I think, perhaps the writer is not comprehensive enough, after all, people are people, computers are computers, computers can not be completely according to People's thinking to run the script. Here, I tell you a better debugging method is to use the annotation symbol "* * * *", comment out some code, observe the operation. To completely eliminate logic errors, no patience is no good, so to calm down, do not worry.

4. Misuse of error suppressor
The error suppressor "@" is often used in places where errors can occur, but the use of a suppressor is too much or is not a good time, and can also lead to white space to avoid it, take a look at the following two PHP scripts:
test1.php
The following are program code:

<?php
@include ("test2.php");
Echo ($var);
?>

test2.php
The following are program code:

<?php
$var = "Hi"//This line of code has errors, no semicolon
$var 1 = "Hello"//Ibid.
?>

Run the test1 to see, the result produces the blank page. Correcting is also very simple, you can remove the suppressors in front of the include function, or correct the errors in the test2.php file.

In fact, the cause of the blank page may be more complex, more difficult to exclude the reasons, listed here is only the most likely to appear, as long as the careful analysis of the code, in fact, the elimination of errors is also very simple things.







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.