Triumphant over PHP7!


I am not a php developer, but I have built a couple websites that utilize the PHP include statement to make a single instance of an item such as a header or footer and use across the whole site.

When php5x was deprecated, the previous statements would no longer work in 7… I consulted with 3 developers I know, and they were unable to provide the answer. I did not give up, and kept scouring the web, as “everyone” said it should work.

After much searching, and an equal amount of non-working statements, I came across the combination of the following 2 posts… 1) How to enable html files to display php code, & 2) Allow_url_include.

From post 1, I added the code in step 4 to the .htaccess file. But since I am running php7.1, the appropriate lines had to be uncommented. (AKA, getting rid of all the other unused lines that are not useful comments.) BUT… initially, it still did not work. Because I was running a different “version” of php. I was so close before, but this is the detail that all the other tutorials left out.

In the below image, the line needed to be changed to compliment the server info.

This was found by creating a page called phpinfo.php. (You can name it whatever you want, but it is easy to find this way.) The only needed line of code is

<?php phpinfo() ?>

This will generate a page of your php settings. By reviewing at this page, I found that my php version is x-httpd-ea-php71. There is no specific line to look at, the path is peppered throughout and only came to me after staring at it for a few minutes.

From post 2, this was my super important takeaway – the old way of doing <?php include(“<file name>”.php) ?> will not work. Use this instead…

 <?php include($_SERVER['DOCUMENT_ROOT']."<file name>.php") ?>

And that is the story of how PHP7 finally worked in my websites. It was “supposed” to work, I couldn’t give up until I found the right combination.

UPDATE: One of the website installations did not respond to the above. It is hosted on A2Hosting, and they use Server Side Includes to allow PHP includes in HTML files…