ypkumar Posted January 19, 2011 Share Posted January 19, 2011 Hello guys, I am a beginner in PHP, so please be gentle. I am building this website for a friend of mine. This website is made up by HTML/CSS. i.e., I have a page made with HTML & CSS. there are a few menus on the page. say Home, About Us, Contact Us, etc., Now I want to separate the page elements (like header/footer) from the page so as its easy to work on. the source is something like this <HTML> <HEAD> <TITLE> My Page </TITLE> <LINK REL="STYLESHEET" HREF="./mystyle.css" TYPE="text/css" /> </HEAD> <BODY> <DIV ID="wrapper"> <DIV ID="header"> <DIV ID="logo"> <UL ID="menu"> <LI> <A HREF="./index.php"><SPAN>Home</SPAN></A> </LI> <LI> <A HREF="./login.php"><SPAN>Login</SPAN></A> </LI> <LI> <A HREF="./contactus.php"><SPAN>Contact Us</SPAN></A> </LI> </UL> <DIV ID="date"> <?php echo Date("d M Y");?> </DIV> </DIV> </DIV> <DIV ID="bodywrapper"> <DIV ID="main"> <DIV ID="content"> THIS IS A TEST! </DIV> </DIV> </DIV> <DIV ID ="clearfooter"></DIV> </DIV> <DIV ID="footer"> © <?php echo date("Y");?> </DIV> </BODY> </HTML> now I will have my content in the DIV called 'content'. now I have separated this one page into three different pages. like this: header.php <HTML> <HEAD> <TITLE> My Page </TITLE> <LINK REL="STYLESHEET" HREF="./mystyle.css" TYPE="text/css" /> </HEAD> <BODY> <DIV ID="wrapper"> <DIV ID="header"> <DIV ID="logo"> <UL ID="menu"> <LI> <A HREF="./index.php"><SPAN>Home</SPAN></A> </LI> <LI> <A HREF="./login.php"><SPAN>Login</SPAN></A> </LI> <LI> <A HREF="./contactus.php"><SPAN>Contact Us</SPAN></A> </LI> </UL> <DIV ID="date"> <?php echo Date("d M Y");?> </DIV> </DIV> </DIV> footer.php <DIV ID ="clearfooter"></DIV> </DIV> <DIV ID="footer"> © <?php echo date("Y");?> </DIV> </BODY> </HTML> and index.php <?php include_once('header.php');?> <DIV ID="bodywrapper"> <DIV ID="main"> <DIV ID="content"> THIS IS A TEST </DIV> </DIV> </DIV> <?php include_once('footer.php');?> Is this the right way to code? I am worried because I have to keep in mind the safety of the website as I have to include a basic login module to this. is there any other style to write this? please do let me know.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/225029-php-page-coding-style/ Share on other sites More sharing options...
webbhelp Posted January 19, 2011 Share Posted January 19, 2011 Just want to say: If you will code XHTML, (And I think you want?) The do never use capitale letters, only small = no caps lock Quote Link to comment https://forums.phpfreaks.com/topic/225029-php-page-coding-style/#findComment-1162253 Share on other sites More sharing options...
QuickOldCar Posted January 20, 2011 Share Posted January 20, 2011 You can just include the content as well. <?php include_once('header.php');?> <div id="bodywrapper"> <div id="main"> <div id="content"> <?php include_once('content.php');?> </div> </div> </div> <?php include_once('footer.php');?> I feel is a good way to do it. Sometimes would like the page different too, so can break in and out of php and call for different header and content area or styles if would like. <?php include_once('header.php'); echo"all php code up top"; ?> <div> html code if need to </div> <?php echo "back into php with some more code"; $variable = 'name your variables but echo it in the html area below'; ?> best practice is to place all html together at the bottom and echo any php into it, or even just a php section that echoes php and html I guess it all just matters on what need to do with it or how complex it is. Quote Link to comment https://forums.phpfreaks.com/topic/225029-php-page-coding-style/#findComment-1162267 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.