A summary of the causes and solutions for blank pages in php.
Many programmers have encountered blank pages when developing PHP. From a comprehensive analysis, the blank pages appearing in PHP programming may be caused by the following reasons:
1. Logical errors
Logical errors are the most difficult to eliminate. On the surface, the code may appear legal and regular, but when it runs, it is unexpected. This aspect is mentioned in many PHP tutorials.
Why? Maybe the writer didn't think comprehensively enough. After all, people are people and computers are computers. It is impossible for computers to run scripts completely according to human ideas.
A better debugging method is to use the comment symbols "/* */" to comment out some codes and observe the running conditions, so as to eliminate errors one by one and finally find the location of the error code. In this case, if you want to completely eliminate logical errors, you won't be able to do it without patience, so you have to calm down and don't be anxious.
2. Undefined behavior
Code:
<?<span>php </span><span>$action</span> = <span>$_GET</span>['id'<span>]; </span><span>if</span>(<span>$action</span> == ''<span>) </span><span>$action</span> = 1<span>; </span><span>if</span>(<span>$action</span> == 1<span>) { </span><span>echo</span>("/<span>$action</span>'s value is 1"<span>); } </span><span>else</span> <span>if</span>(<span>$action</span> == 2<span>) { </span><span>echo</span>("/<span>$action</span>'s value is 2"<span>); } </span><span>//</span><span> www.jbxue.com</span> ?>
If the $action variable is empty, set it to 1, then determine the value of the $action variable and make different events. Of course, what will PHP do if $action is neither equal to 1 nor equal to 2? The answer is - nothing will be done, so a blank page will be generated. Once you know the cause, the solution is easy.
The solution to this problem is very simple. Just add an else after the if module and print some information.
3. Syntax error
If there is a grammatical error, there will usually be an error message. Why is it blank? (Script Academy www.jbxue.com)
Of course, this is just an individual phenomenon. In some homepage spaces, if you write PHP with grammatical errors, it will not give any prompts.
Solution:
Test locally before uploading the file to find out the wrong code and correct it.
4. Abuse of the error suppressor @
The error suppressor "@" is often used where errors may occur. However, if the suppressor is used too much or at the wrong time, it may also lead to blank spaces. Take a look at the following two PHP scripts:
test1.php:
<?<span>php @</span><span>include</span>("test2.php"<span>); </span><span>echo</span>(<span>$var</span><span>); </span>?>
test2.php:
<?<span>php </span><span>$var</span> = "Hi" <span>//</span><span>这行代码有错误,没有分号</span> <span>$var1</span> = "Hello" <span>//</span><span>同上</span> ?>
Run test1 and see, the result is a blank page. Correction is also very simple. You can remove the suppressor in front of the include function, or correct the error in the test2.php file.