Forum Moderators: coopster

Message Too Old, No Replies

PHP include in HTML

What am I doing wrong here?

         

Corpocracy

6:27 am on Jan 8, 2008 (gmt 0)

10+ Year Member



Alright, so I've researched this online at a few different places including a couple topics that had similar problems that were posted here. But, it's still not working and I'm a bit confused.

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

and the source code still shows the php include statement.

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.

Habtom

6:36 am on Jan 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The point is the including file should be PHP executable meaning index.html needs to be index.php.

Or if that is generally ok with you, you could Parse PHP with HTML file extension [webmasterworld.com].

. . . and welcome to WebmasterWorld.

Wilf

9:24 am on Jan 8, 2008 (gmt 0)

10+ Year Member



If the <?php statement is appearing in your markup then PHP isn't installed properly on your machine.

jatar_k

12:59 pm on Jan 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld Corpocracy and Wilf

I would say it was not configured properly as Habtom's link will clarify

The Contractor

1:12 pm on Jan 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You have to parse .html files as PHP. Many hosting control panels allow you to change this in Apache handlers or you can do this via .htaccess.

[edited by: The_Contractor at 1:16 pm (utc) on Jan. 8, 2008]

coopster

4:24 pm on Jan 8, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Another related thread with some good reading:

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.

caspert ghost

7:31 am on Jan 9, 2008 (gmt 0)

10+ Year Member



index.html should really be .php

<?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.

minverasolutions

1:03 am on Jan 18, 2008 (gmt 0)

10+ Year Member



So, I have tried that, but I'm wondering if its possible to do this somehow.

<!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]

surrealillusions

1:25 pm on Jan 18, 2008 (gmt 0)

10+ Year Member



minverasolutions - depending on how you style the page, theres no definate answer on that i think. If your putting the divs on top of each other in a coloumn, then that wont work, but if its positioned absolutely using CSS, then i suppose you can put the content at the top and the less important things below, and the CSS will style it appropiately.

hope that helps

:)