Forum Moderators: coopster
I have a .html file and I'm trying to include a few other html files into it. This is the jist of the code I have now:
index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php include("header.html");?>
Here is some content
</body>
</html>
header.html
<div>
content lalala
</div>
When I open the page, all I see is
Here is some content
Now, I've tried renaming the header.html to header.php, tried single quotes (') and double quotes ("). I thought I may have done the url incorrectly so I tried writing it a couple of different ways ("http://www.domain.org/header.html", "/header.html"). So, basically, nothing's worked and I would really appreciate any help you guys have. I've done a decent amount of website work before, but this is my first time dealing with php so I'm a bit confused with how it works and how to solve the problem.
Thanks.
Or if that is generally ok with you, you could Parse PHP with HTML file extension [webmasterworld.com].
. . . and welcome to WebmasterWorld.
Do I have to change .html to .php? [webmasterworld.com]
AddHandler is really the correct approach but it depends on which type (cgi versus module) and which version of PHP you are running. Details in the link provided.
<?php include("header.html");?>
make this 3 lines to be acurate:
<?php
include ('header.php');
?>
I say this because you can not have any spaces before or after the closing?> php code.
if your going to work with php (even if the majority of your code is html, you should genneraly name them .php, this is also a good security practice as you can prevent users from directly accessing your include pages:
in the top of each page included:
<?php
if (!defined ("NameYourDefine")){
echo "YourMessage";
exit ();
}
?>
inside index.php just above your include link add:
<?php
define ("NameYourDefine",1);
?>
and that sjpuld do what you are looking for.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TITLE HERE</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="container">
<div id="nav-container">
<a href="index.html">HOME</a> -
<a href="../forums/">FORUM</a> -
<a href="downloads.html">DOWNLOANDS</a> -
<a href="links.html">LINKS</a> -
<a href="about.html">ABOUT</a>
</div>
<div id="left">
<h1>Main<small>Menu</small></h1>
<ul>
<li>Lorem ipsum dolor sit amet,</li>
<li>Consectetuer adipiscing elit.</li>
<li>Morbi vulputate placerat libero.</li>
<li>Curabitur faucibus ipsum non.</li>
<li>Praesent consequat sem.</li>
<li>Donec mollis ipsum ut .</li>
<li>In tempus est ut arcu.</li>
</ul>
<h1>Our<small>Sponsors</small></h1>
<div class="box-bg">
<img src="images/ct_affiliate.jpg" alt="Template made by example.com" />
<img src="images/ct_logo.jpg" alt="Template made by example.com" />
</div>
<h1>Main<small>Menu</small></h1>
<ul>
<li>Nulla auctor orci a risus.</li>
<li>Nunc ultricies odio vitae diam.</li>
<li>Pellentesque fringilla velit.</li>
<li>
<?php
include ('header.php');
?>
</li>
<li>Nam lobortis consectetuer leo.</li>
<li>Sed sollicitudin nisl nec odio.</li>
</ul>
</div>
</div>
</body>
</html>
look at where the php script is. Is this possible?
[edited by: eelixduppy at 1:28 pm (utc) on Jan. 18, 2008]
hope that helps
:)