PDA

View Full Version : Php question -> Include & require vs header



dpgtfc
29 Mar 2007, 08:34 PM
So I am building a database driven, dynamic web page, and I only have a small grasp on PHP. Most of my scripts are separate and are called as needed.

In many of the examples I have seen, the script uses a header( blahblah.php) or some such, which I'm not sure I understand the difference between includes/requires and these headers.

Can anybody explain this to me in simple terms? The PhP manual online doesn't clarify it for me.

Alan
30 Mar 2007, 10:37 PM
It's quite simple actually.

include("file.php");

This will include the file into the page. If the file isn't there, it will ignore it and continue to load the rest of the page.

require("file.php");

This will insert the file into the page, exactly the same as the include function. However, if the file doesn't exist. It will cause an error and kill the page, so nothing will be loaded.

As for the header function. This sends HTTP request headers to the server. This can be used to specify where you would like the browser to go, or what format the content of the page will be displayed in... such as html, plaint text or an image etc... or control the cache etc...

It has many uses. You should google them to find out more.