Summary of Causes and Solutions of Blank Pages in php

  • 2021-07-07 06:45:25
  • OfStack

Many programmers have encountered blank pages when developing php. Comprehensive analysis shows that blank pages in php programming may be caused by the following reasons:

1. Logic error

Logical errors are the hardest to eliminate. On the surface, maybe the code is legal and formal, but it doesn't run as expected. Why? Maybe the writer doesn't think comprehensively enough. After all, people are people and computers are computers. Computers can't run scripts completely according to people's ideas. Here, I tell you a better debugging method, that is, use the annotator "/**/", comment out some codes, observe the running situation, so as to eliminate errors one by one, and finally find the location of error codes. In this case, if you want to completely eliminate logical errors, you can't do without patience, so you should calm down and don't worry.

2. The behavior is undefined

Look at the following 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 and make different events. Of course, what would PHP do if $action was neither equal to 1 nor equal to 2? The answer is-nothing will be done, so a blank page will be produced. Knowing the reason, it is easy to solve it. To solve this problem, it is very simple to add an else after if module, and print some information.

3. Grammatical errors

You may ask, if there is a grammatical error, 1 will have an error prompt, how can it be blank? Of course, these are only a few isolated phenomena, and in some homepage spaces, if you write PHP with grammatical errors, it will not be prompted. Troubleshooting is also easy. Test locally before uploading files to find out the wrong code and correct it.

4. Abuse of error mask @

The error suppressor "@" is often used where errors can occur, but overuse or misuse of the suppressor can also lead to white space. Take a look at the following two PHP scripts:

test1.php:


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

test2.php:


<?php
$var = "Hi" // There is an error in this line of code and there is no semicolon 
$var1 = "Hello" // Ibid. 
?>

Run test1 to see, and the result is a blank page. Correction is also simple. You can remove the suppressor in front of the include function or correct the error in the test2.php file.


Related articles: