From the course: PHP for Web Designers

Why is my page blank or incomplete? - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Why is my page blank or incomplete?

Imagine this scenario. You've just uploaded a PHP page to your website, but when you view it in the browser, it's completely blank like this one here. Even if you view the source code, there is nothing there. It's completely blank, absolutely nothing. This actually happens quite a lot. Let's examine why and what to do about it. Let's go into my editing program. Here is the original page and it's certainly not blank. Let's go to another page. This one has a similar problem, but there does seem to be something there. We've got this white strip at the top and we'v got a background image. So if we look at the source code, we've got the doc type there. We've got the head. And we've got the beginning of the body, but everything is truncated after that first div tag. The reason that this has happened in both cases is because display errors has been turned off in the PHP configuration. And this often happens when you decide to use your remote server to test pages rather than installing a local testing environment. And it can also happen with a page that works locally, but fails when you upload it. Many hosting companies turn off the display of errors these days as a security measure. And to simulate this situation, I've added a .ht access file to the 07_02 folder, to disable the display of error messages. So if you're faced with this type of situation, the way to deal with it is to turn on the display of error messages temporarily in your remote server. We do that within the page itself, the very first thing that you put after the opening PHP tag is ini_set, then open parenthesis, and in quotes display_errors. Then a comma and in quotes one. And let's just copy that. We'll put it in the other page, and let's save both pages and go back to the browser, and in the case of this page when I reload it, we still get a blank page. The reason for that is there is a syntax error in this page. Turning on the display of errors temporarily, using any set doesn't work if there's a syntax error. A syntax error just kills the page completely. But if we go to the other page that was truncated, and reload, we then get the error messages telling us what's happened. And this is extremely useful for debugging the problem. So, if you've got a completely blank page, try turning on the display of errors using any underscore set then display errors with the value of one. But if your editor's syntax checking doesn't reveal the cause of the problem, there's nothing else for it, than to test it on a server which is configured to display error messages. This ini_set, doesn't work if you've got a syntax error. In fact, my editor tells me that there is a syntax error here on line three. What's missing is the closing parenthesis after string to lower. That syntax error will go away and if I save that page, refresh the browser, there it is, it's displayed. Everything is fine, so it was the syntax error that was causing that blank page. For other errors, turning on the display of errors temporarily using any set at the top of your script, is an extremely useful work around. But don't forget to remove that line once you've fixed the error. Another problem could emerge at a later date, and you don't want to reveal it to everyone who visits your site.

Contents