Jump to content

php includes in shtml files


heldenbrau

Recommended Posts

I want to inlude some php includes in my shtml files.

 

I have the following line added in the head section of my shtml page.

 

<MIME TYPE Extension application/x-httpd-php.html>

 

But when I open the page, the php doesn't work.  The code is not displayed though, it is only displayed in the source. 

 

The code that is in the include is

<?php
session_start();
if (!isset($_SESSION['username'])) {
$username=($_SESSION['username']);
  echo"You are logged in as $username";
}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/169071-php-includes-in-shtml-files/
Share on other sites

You need to tell Apache (assuming that's what you are running) to let the PHP parser parse the page.

 

Put this in your .htaccess file

 

RemoveHandler .shtml
AddType application/x-httpd-php .php .shtml

 

The 'x-httpd-php' part may be different on your server. When I was on a free host, there had different tiers of PHP security, so some people used x-httpd-phpv2 on so on. If the example above doesn't work, you'll have to check with your host.

 

Also remember that that .htaccess file when apply to every sub-directory from the directory it's in as well.

I am using apache on my laptop to test a website.  It is version 2.2.

 

I have added those lines to the httpd file.  It has made an improvement, the code is displayed on the webpage, but the code isn't executed. 

 

It is like it is being done in the wrong order, like PHP first, then shtml, so the php is included after it has been exectuted, so only shows as an html page with the php code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.