Reasons and solutions for php blank pages in the php tutorial, and blank php pages

Source: Internet
Author: User

Reasons and solutions for php blank pages in the php tutorial, and blank php pages

Summary of causes and solutions for blank pages in php.

Many programmers encounter blank pages during php development. For comprehensive analysis, the following reasons may be caused by blank pages in php programming:

1. logical error
Logical errors are the most difficult to eliminate. On the surface, the Code may be legal and formal, but it is not unexpected to run. This is mentioned in many php tutorials.
Why? 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.
A better debugging method is to use the annotator "/**/" to comment out some code and observe the running conditions to eliminate errors one by one, and finally locate the error code. In this case, if you want to completely eliminate logical errors, you can't do it without patience.

2. The behavior is undefined.
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");} // www.jbxue.com?>

If the $ action variable is empty, set it to 1, and then judge the value of $ action variable to make different events. Of course, what will PHP do if $ action is neither 1 nor 2? The answer is-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. Simply add an else after the if module and print some information.

3. Syntax Error
If a syntax error occurs, the error message is displayed. How can this problem be left blank? (Script school www.jbxue.com)
Of course, this is only a few examples. In some homepage spaces, if you write PHP with syntax errors, there will be no prompts.

Solution:
Test locally before uploading files to correct the error code.

4. abuse 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:

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

Test2.php:

<? Php $ var = "Hi" // This line of code has an error, 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.


Php blank pages
Print all. When the blank page is incorrect, add the following to the PHP file: <? Php error_reporting (E_ALL);?>
Error, Note, Warning, and other information are displayed.
PHP blank page problems.
It's hard to answer questions without output.

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.