Received Wed, 28 Oct 2009 03:18:55 PHT
HTTP/1.1 200 OK headers displayed in HTML pages using PHP include() function. Solution to such errors and how to solve [function.include]: Failed opening PHP error
Working environment that resulted in error of HTTP headers displayed
On openSuSE LAMP, always updated version, I have may adsense included by SSI using PHP function() on all pages. Also using same method to add footers to many pages or other text modules. I had this system working correctly for over 2 years. After the most recent PHP security update, the full HTTP header was displayed immediately preceding each text module included.
PHP function include() successfully in use on my site prior to the last PHP5 security update
I had two versions to include text modules:
- using relative paths to the included file. Hence something like: include(../../include_folder/path_to_include_file.tpl)
- the preferred method was including the full URL to the text module to be included. include(http://www.kriyayoga.com/include_folder/path_to_include_file.tpl).
That latter option of course does require the php.ini to be properly configured:
allow_url_fopen = On
allow_url_include = On
The benefits of having a URL included is obvious: The path works in ANY possible sub-sub-sub_folder combination. In a web project with a several ten thousand files it is vital to have a path system that works across all files/folders/subfolders to be failsafe as much as possible. The risks of cross scripting are known and properly taken care of using available server security features and server security tools = snort and mod_security.
Errors occurring after update

Displayed http headers immediately before each SSI text module included with PHP include() in the HTML pages looked like below:
HTTP/1.1 200 OK Date: Fri, 23 Oct 2009 09:05:19 GMT Server: God is Love Last-Modified: Wed, 21 Feb 2007 09:42:55 GMT ETag: "a7bf4-22e-429f9620605c0" Accept-Ranges: bytes Content-Length: 558 Connection: close Content-Type: text/plain; charset=utf-8 X-Pad: avoid browser bug
At first there were no error reporting found in my error_log. After modifying the php.ini, I finally got the following error displayed for those include files using relative paths. All those files using URLs still showed NO error at all in the logs.
The http header was usually displayed the first time a page was loaded. After reloading same page the http headers disappeared on all SSI text modules. Also in some cases of first page load the http header was NOT shown on the HTML page. Hence it was quiet difficult to reproduce an error as only about 50% of pages loaded showed the error.
Error log file entries found for one part of the PHP include() errors
[Sat Oct 24 05:50:58 2009] [error] [client 70.137.129.213] PHP Warning: include() [function.include]: Failed opening '../../includes/path_to_include_file.tpl' for inclusion (include_path='.:/usr/share/php5:/usr/share/php5/PEAR') in /server_path_to_document_root/htdocs/actualities/introduction.htm on line 23, referer: http://www.kriyayoga.com/pd/pdtop.html
For any unknown reason, may be even a bug in the new security update, the HTTP header is displayed. There was nothing I have changed in all past months in my PHP.ini nor server configuration at all. Google search revealed no solution, nor did a cross post in 2 of the worlds largest webmaster forums.
An in depth study of the entire php.ini and the various PHP include() or similar functions finally was leading to the solution.
As a general rule for all such problems:
Large problems such as this http header and include() errors almost always are caused by smallest causes!
Thus a fix almost always is possible using smallest changes or adaptations / corrections.
In the php.ini file is a default configuration line for include paths:
include_path = ".:/usr/share/php5:/usr/share/php5/PEAR
In all the past years, there was no need to add or change any of these paths. To fix both problems of PHP include() failing and http headers displayed, I added the server path to my document root ( server root ):
include_path = ".:/usr/share/php5:/usr/share/php5/PEAR:/home/www/your_htdocs"
Then I changed ALL included relative paths and/or URLs to start at document root ( server root ) without the preceding slash!
Example PHP function include() with URL for footer modules residing in /footer_folder on my server:
include('http : // www . kriyayoga . com/footer_folder/footer_wallpapers_x.tpl') (without spaces in URL path!
are now changed to:
include('footer_folder/footer_wallpapers_x.tpl')
And example relative paths used for PHP function include():
include(../../include_folder/path_to_include_file.tpl)
now has become:
include(include_folder/path_to_include_file.tpl)
WARNING: An absolute path on server like include(/include_folder/path_to_include_file.tpl) = path starting with a slash for server root will fail to work in php include. This absolute path only works in HTML paths NOT in php include paths!
This above solution is a clean and correct solution and NO workaround! It serves all purpose and also gives you ONE single include path to use as all include paths start at server root - without slash - no matter from there this function is used in your sub-sub-folder system.
All you need to do is to find all your previous included() codes across all forums and HTML files and replace all paths with the new code.
Love and bliss
hans




