Common causes and solutions for PHP blank pages

Source: Internet
Author: User
Tags blank page
Compiling PHP will inevitably lead to errors. In fact, it is not difficult to solve the problem. The most difficult solution is to have a blank page. Let's think about it. if an error occurs when you write PHP, you can correct it according to the error prompt. If PHP does not show you anything, isn't it difficult for the author? Next, I will summarize the PHP blank page solution and the production of PHP, which will inevitably cause errors. In fact, it is not difficult to solve the problem. The most difficult solution is to have a blank page. Let's think about it. if an error occurs when you write PHP, you can correct it according to the error prompt. If PHP does not show you anything, isn't it difficult for the author? Next, I will summarize the solutions and causes for the blank pages of PHP when writing PHP. Of course, I am not very good at writing PHP, so if there is an error, please do not hesitate to point it out.

1. The action is not defined.
Let's take a look at the following code:
[Code]
$ 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 ");
}
?>
[/Code]
You can understand this code, that is, if the $ action variable is empty, set it to 1, and then judge the value of the $ action variable to make different events. Of course, what will PHP do if $ action is neither 1 nor 2 ?? -- Nothing will be done, so a blank page will be generated. Knowing the cause makes it easy to solve the problem. The solution to this problem is very simple. you can add an else after the if module.

2. Syntax error
You may ask, if a syntax error occurs, an error is Prompted. how can this problem be left blank? Of course, this is only a few examples. in some homepage spaces (such as the free space of www.ju.com in China), if you write PHP with syntax errors, there will be no prompts. It is also easy to solve. before uploading a file, test it locally and find out the wrong code to correct it.

3. logical error
This problem is the most difficult to eliminate. on the surface, the code may be legal and formal, but it is not unexpected to run. Why? I think, maybe it is not comprehensive enough for the author to think about it. after all, the person is a person, the computer is a computer, and it is impossible for the computer to run the script completely according to the person's ideas. Here, I will tell you a better debugging method, that is, to use the annotator "/**/" to comment out some code and observe the running situation. If you want to completely eliminate logical errors, you can't do it without patience. so you have to calm down and don't worry.

4. misuse of the error blocker
The error blocker "@" is often used in places where errors may occur. However, if the blocker is used too much or is not used frequently, it may also lead to blank spaces, let's take a look at the following two PHP scripts:
Test1.php

The following is the program code:

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

Test2.php
The following is the program code:

$ Var = "Hi" // this line of code has an error with no semicolon
$ Var1 = "Hello" // same as above
?>

Run test1 and check that a blank page is displayed. Correction is also very easy. you can remove the prefix of the include function or correct the error in the test2.php file.

In fact, the reason for generating a blank page may be more complicated and more difficult to exclude. the reason listed here is the most likely one. if you carefully analyze the code, in fact, troubleshooting errors is also very simple.

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.