Chrome doesn't display HTML content in PHP file when PHP is not running

Hi,

I have an installation page (install.php) for my application. On that page, I check if PHP is up and running on the server. Pretty much like WordPress install page does. So, if PHP is not running on the server, the page displays a warning saying “PHP is not running”, if PHP is running, it displays the install form. When I test it (on my local server) by disabling PHP, the page displays fine in Firefox and IE, but it displays only the code in Chrome and Safari as if you are viewing the source code. Is there any way to make it display fine on Chrome and Safari too or is this kind of a dead end?

Thanks for any ideas.

EDIT - SOLVED: I was able to test it on a live server and the issue does not happen there. I guess it is the way Chrome behaves for local files.

How… exactly do you do that? If PHP isnt running on the server, the PHP isnt consumed.

1 Like

As it is also used in WordPress’ install.php, I use

<?php
if (false) { ?>

... PHP is not running, display warning message using pure HTML/CSS...

<?php } ?>

... display install form...

What the above code does is to display the install form if PHP is running, otherwise display a warning. I also use JS to hide the install form’s HTML in that case.

But if PHP is not running on the webserver, that code would output the code literally. You would see the <?php ....?> bit.
Check your source.

If the PHP engine is not running, nothing consumes the <?php ...?> tag, and the form is still displayed.

1 Like

Might it be that the browser parses the HTML tags and text but treats the PHP as comments? i.e. It looks like the page but a closer look would prove the PHP stuff is missing.

It’s possible it’s confusing the PHP for XML-style tags; but that’s a browser-dependant rendering function;not actually hiding the code.

Yes, the PHP code is visible in the source but not in the browser window. I was not trying to hide the code, I was trying to render it correctly in Chrome. I tested it on my local server and on a live server by disabling PHP. On local server, Firefox and IE displayed the .php page fine. Chrome and Safari displayed it as code. On live server, all browsers displayed the page fine. They rendered the HTML/CSS as a normal page and ignored PHP code which is what I was trying to achieve. Also, I hid the form (if PHP is not running) using JS within the IF statement. You can try viewing the install.php page of WordPress by disabling PHP on your server/localhost and you will see what I mean. Unlike mine, that page still displays the broken form code if PHP is not running.

Yes, I guess that’s the case.

My conclusion is that Chrome (or webkit) behaves differently for pages hosted on localhost and on a live server. Anyway, my issue is solved and thanks for your contributions.

Actually, @StarLion is correct in that they are considered to be XML tags, which the browser doesn’t render. (I hadn’t had my caffiene :coffee: when I wrote that).

Anyway, the main thing is that the server needs to be running and the pages need to be accessed from there (i.e. localhost) not from the OS’s default filesystem browser.