Basic PHP Includes.

liunx

Guest
Am i doing this right? i preview it locally on my machine and it doesnt show the header.php at the top but if i upload it to my space online it does..<br /><br />heres the index.php code:<br /> <br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br /><title>PHP Include Test</title><br /><style type="text/css"><br /><!--<br />body {<br /> margin-top: 0px;<br /> margin-right: auto;<br /> margin-bottom: 0px;<br /> margin-left: auto;<br /> font-size: 0.8em;<br /> color: #999999;<br /> text-align: center;<br />}<br />#header {<br /> width: 700px;<br /> position: relative;<br /> height: 80px;<br />}<br />#content {<br /> background-color: #CCCCCC;<br /> width: 700px;<br /> position: relative;<br /> height: 500px;<br />}<br />#wrapper {<br /> margin-top: 0px;<br /> margin-right: auto;<br /> margin-bottom: 0px;<br /> margin-left: auto;<br /> height: auto;<br /> width: 700px;<br /> position: relative;<br />}<br />#footer {<br /> width: 700px;<br /> position: relative;<br /> height: 80px;<br />}<br />--><br /></style><br /></head><br /><body><br />        <div id="wrapper"><br />               <?php include("header.php"); ?><br />               <div id="content"></div><br />               <div id="footer"></div><br />         </div><br /></body><br /></html><!--c2--></div><!--ec2--><br /><br />(i know the css is in the document and not linked in, just playing about and couldnt be arsed to do it properly)<br /><br />here is the header code:<br /><br /><br /><br /> <br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br /><html xmlns="http://www.w3.org/1999/xhtml"><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br /><title><br /></title><br /><style type="text/css"><br /><!--<br />p {<br /> font-size: 0.8ems;<br /> color: #CCCCCC;<br /> font-family: Verdana, Arial, Helvetica, sans-serif;<br />}<br />#header {<br /> background-color: #993333;<br /> height: 80px;<br /> width: 700px;<br /> position: relative;<br />}<br />--><br /></style><br /></head><br /><body><br />     <div id="header"><br />          <p>welcome to php include test blah blah blah blah blah</p><br />     </div><br /></body><br /></html><!--c2--></div><!--ec2--><br /><br />both files are saved as .php too.<br /><br />am i missing something out?<br /><br />thanks<!--content-->
yeah...<br /><br />The header is meant to contain the following:<br />- DOCTYPE<br />- <head> section<br />- opening <body> section<br />- any page elements which is consistent across the site<!--content-->
By the looks of it you're including a full document inside another document. That's create invalid markup. You'll see if you look at the markup it generates.<br /><br />You don't have to (and shouldn't) include a full doc structure in all the HTML documents you include. Just the repeating elements. One piece from this file, one piece from that file and it get stitched together when the PHP script is requested.<!--content-->
dumb it down a bit<br /><br />for example to write <br /><br />I own a _____ (and have the blank filled in from an include file)<br /><br />You would have your base file<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><html><br /><head><br /><title></title><br /></head<br /><body><br />I own a <?php include("file.php"); ?><br /></body><br /></html><!--c2--></div><!--ec2--><br />And your include file<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->car<!--c2--></div><!--ec2--><br /><br />Thats it, no other tags surrounding it (put all your styles into an external css file)<!--content-->
 
Top