Application works fine on localhost but fails on web server

If you ever run into situation, that your application works fine on localhost (or one of webhosting) but fails completely on webhost (or another server) then first thing, you should look for, is to check, if you don’t have an extra XHTML line in on of your files that you’re loading using include or require.

Meaning, that your loading and PHP-parsing these files. Because problem doesn’t exist, if you’re loading this files as simple text files, using file_get_contents for example.

Situation, I’m talking about most times causes a PHP syntax error saying, that there is an unexpected T_STRING in first line of one of the files used in an application.

If you look to this file, you may find following line as first one:

<xml version="1.0" encoding="iso-8859-2">

This usually happens, when environment, where your application works, has PHP short_tags enabled in configuration, while on failing webserver most probably this config option is disabled. PHP tries to parse it and fails. Since this is XHTML-related problem, most times it comes around template files or similar.

There are many questions here, but only one answer.

I don’t know, why some editors adds this line, when creating new XHTML file, while others doesn’t add them. I don’t know, why PHP parses this line correctly (doesn’t come out with any error), when short tags are enabled and while fails, when they’re disabled — in both cases this line seems to be unparsable, as it does not contains valid PHP code.

Finally I don’t know, if removing this line will or won’t make your file / app valid and go through XHTML validators without any problems — i.e. if it is or isn’t necessary as a part of valid XHTML file. But the only answer, I know to all these concerns, is — remove this line.

That’s it. I tested layout file containing this line, being loaded and parsed via require, on both simple PHP app and large framework-based (Yii of course) project. When short tags were disabled, both apps failed. And removing this line was the only remedium in this case.

BTW: You can enable or disable short tags, no matter what your server configuration is, by adding:

php_value short_tags off

to .htaccess file placed in root folder of your PHP application.

That’s all I know for now. Go ahead, and write in comments, if you have any other solution to described problem or if you can add anything here.

Leave a Reply