Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi all,

I have created a file in Dreamweaver that is going to be a header include, as follows:

 

<?php
// Di's Soft Furnishings
// header.html
// The header file
ob_start();
session_start();
if (!isset($page_title))
{
$page_title = 'Di\'s soft Furnishings';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $page_title; ?></title>
</head>
<body>
<?php
echo '<p>hello</p>';
?>
</body>
</html>

 

 

I saved it as header.html and run it through local host (XAMPP). It displayed the ';?> after the hello. I then save the same code as header.php and run it through local host and it was perfect.

 

Question: Does it matter if I save a file as html or php? I also understood that php could be placed within html OK. It doesn't seem to be the case here.

 

Thanks for any help.

Paul

Link to comment
Share on other sites

If your header.html file were included in another .php file, it would work okay. But on it's own, the server wouldn't run it through the PHP interpreter because it doesn't have a .php extension. The server uses the extension to determine whether it needs to send it through the interpreter. So, if you had an index.php with include 'header.html'; it should work fine because the index.php file will be run through the PHP interpreter, along with any files it includes.

Link to comment
Share on other sites

 Share

×
×
  • Create New...