Jump to content

PHP Newbie questions regarding functions usage


deepman007

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ;

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.