amroawad Posted December 20, 2008 Share Posted December 20, 2008 Hi, I'm completely new to coding and I'm trying to learn some stuff by doing it but I would like to learn it in the best possible way. I have created a header.php, footer.php and an index.php. But where should I add the html tags like <html> blabla I will layout what I have now: Header.php : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="" /> <link href="CSS/Stylesheet.css" rel="stylesheet" type="text/css" /> <title>Untitled 3</title> </head> <body> <div align="center"> <div id="main"> <div id="header" align="left"> <div id="header_name"> WebProject </div> <div id="header_slogan"> For my next big projects </div> </div> <div id="menu"> Menu </div> </div> </div> </body> </html> <?php ?> Index.php : <?php include("includes/header.php"); include("includes/footer.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="" /> <link href="CSS/Stylesheet.css" rel="stylesheet" type="text/css" /> <title>Untitled 3</title> </head> <body> <div align="center"> <div id="content"> Content </div> </div> </body> </html> Footer.php : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="" /> <link href="CSS/Stylesheet.css" rel="stylesheet" type="text/css" /> <title>Untitled 3</title> </head> <body> <div align="center"> </div> </body> </html> <?php ?> When I load the page in the browser everything works however I'm seeing three times the <html> until </html> in the source code. What's the best and cleanest way to do this since I don't think it should be necessary to declare html tags three times. Can someone help me out? Thanks Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 20, 2008 Share Posted December 20, 2008 Thats because when you include a file - it simply sort of "dumps" that file into the position where the current code is. So your header probably wants to be <html> | \/ <body> and then the footer: </body> | \/ </html> So that your index can be "content" as such. index.php: <?php require("header.php"); place code here to run in the content section require("footer.php"); ?> jsut a note, remember to make sure that your include files end in php ( even if you have header.inc.php) because if someone requests the inc file from outside your script it will show them the source code. Quote Link to comment Share on other sites More sharing options...
amroawad Posted December 20, 2008 Author Share Posted December 20, 2008 Can you explain the last peace more in detail please? Should I add the include statements to the end of the index file? Is that what you are saying? Thanks for the help so far. Quote Link to comment Share on other sites More sharing options...
chronister Posted December 21, 2008 Share Posted December 21, 2008 You want to include the items where you want them to appear. I do this same kind of thing, but a little bit different. header.php <html> <head> <title><?php echo $pageTitle; ?></title> </head> <body> <!-- The page content will appear here.... --> <?php function footer(){ ?> </body> </html> <?php } // end function ?> By doing it this way, I can keep my main layout page in 1 file. I drop out of html an into php to start the function and then again at the end to close the function. This allows me to view the page in a wysiwyg editor to see how it looks. I always develop in code view, but use design view to see how things look. Then on my pages I do this. index.php <?php $pageTitle = 'My HomePage'; include($_SERVER['DOCUMENT_ROOT].'/header.php'): ?> The body content goes here..... <div> a div tag</div> <ul> <li>Item1</li> <li>item2</li> </ul> <?php footer(); ?> So every page I create starts with <?php $pageTitle = ''; include('header.php'); ?> I generally use $_SERVER['DOCUMENT_ROOT] inside the include so that I don't fool with getting to the right directory. It is sort of the same as using a forward slash in html to denote start from root. And each page ends with <?php footer(); ?> HOpe this helps ya Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 21, 2008 Share Posted December 21, 2008 We have now created a template. header.php footer.php index.php The index page will be created the same amount off time that there are links, and named the same as the link names in the header.php page. Then were have a 5 page website ready to go. Each page well be altered but keeping the look and fell off every other page. color,table size, ect ect ect. If you need to use pictures then use a couple that can be used agin and agin on all pages. if you need to add another link just alter the header.php and all other pages get the same look. The same with the footer.php page. You can go as dynamic as you want, As you been shown below post's, But to be onset all the years i have done programming, It best to keep it as simple as passable. Remember it not just html and css that you need to learn also you need to study css. unfortunately seo a web site can make you alter the look and fell off the complete web site it self, This is due to the amount off keywords needed, And the design that needs to be created to out weigh your competition to get high ranked in search engines. good luck. index.php <?php include("header.php"); ?> <html> <head> <title>My Test Page</title> </head> <body> <h2>Hi there im redarrow this is my body of this exaple.</h2> </body> </html> <?php include("footer.php");?> header.php <p></p> <center><h1>My Header Logo</h1></center> <p></p> <table align="center"> <tr> <td><a href="page_1.php">Page 1</a><td> <td><a href="page_2.php">Page 1</a><td> <td><a href="page_3.php">Page 1</a><td> <td><a href="page_4.php">Page 1</a><td> <td><a href="page_5.php">Page 1</a><td> </tr> </table> <p></p> footer.php <p></p> <table align="center"> <tr> <td align="center"> <hr></hr> @www.my_website.com design by redarrow@my_website.com <hr></hr> </td> </tr> </table> <p></p> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.