deepman007 Posted February 25, 2008 Share Posted February 25, 2008 Hi Here's my situation, I have created a website using Xhtml & CSS, the problem is that the header, footer and other constant contents are re-loaded in very page that I have created and I think that will slow the loading speed of the pages. So, I decide to try php where you can re-use the header, footer in every page and I don't have to go edit in every page. My question is which function in PHP should I use to re-use the header, footer , etc ? Include, require, include-once, require once ? My files are: header.php, footer.php, ...etc In index.php <?php include( "header.php") ?> middle content <?php include("footer.php") ?> is set up correct? Thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 That looks fine. Look here for the difference between include and require http://us.php.net/include/ I would imagine you would want to use include. Quote Link to comment Share on other sites More sharing options...
duclet Posted February 25, 2008 Share Posted February 25, 2008 My philosophy on things since that unless you know for a fact that you will be including a file more than once, I always use the *_once functions. I also tend to use the require* functions since I want to see a fatal error if a file is missing since to date, all of my includes are "require"d. Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 Include will load the page even if the contents of the include are broken Require will stop the page-load if the contents is broken and display an error include-once don't seem necessary for what your trying to do nor require-once your best bet would be include, and your setup looks appropriate for what your trying to do include("header.php"); <~ You need the ; Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 But then your page will error even if the header is missing, at least with a include your page will display and usually headers/footers are not important. Quote Link to comment Share on other sites More sharing options...
deepman007 Posted February 25, 2008 Author Share Posted February 25, 2008 Which function would be the best practice choice for developers in this case ? Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 I thought we just answered that. Read the pros/cons and decide what you want to do. Quote Link to comment Share on other sites More sharing options...
deepman007 Posted February 25, 2008 Author Share Posted February 25, 2008 Sorry, I wasn't sure. I have another question, As for the CSS file, do I have to break it to header css, footer css and middle css or I can still use all as one css file ? Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 Just once should be all thats necessary. Quote Link to comment Share on other sites More sharing options...
revraz Posted February 25, 2008 Share Posted February 25, 2008 Again, this is all preference and style decisions you have to make. I like seperate CSS DIV IDs because for me it's easier to manipulate it exactly how I want it. Sorry, I wasn't sure. I have another question, As for the CSS file, do I have to break it to header css, footer css and middle css or I can still use all as one css file ? Quote Link to comment Share on other sites More sharing options...
timmy0320 Posted February 25, 2008 Share Posted February 25, 2008 So while I'm at it, for the files in an include directory, you should use require_once is what ya'll are saying? Just a little clarification for future reference for myself. Quote Link to comment Share on other sites More sharing options...
deepman007 Posted February 25, 2008 Author Share Posted February 25, 2008 thank you for the answers. What's the files directory should be? Should I put all the include files in a include folder or just put it all at the root folder? Cause for html files, I put all those pages in one folder with the exception of images and css. Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 thank you for the answers. What's the files directory should be? Should I put all the include files in a include folder or just put it all at the root folder? Cause for html files, I put all those pages in one folder with the exception of images and css. That's your preference, but because of my computer organization OCD, I tend to make folders for includes. 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.