00:00
00:00
Newgrounds Background Image Theme

Ryor just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Php: Including Files

1,700 Views | 2 Replies
New Topic Respond to this Topic

Php: Including Files 2007-05-07 09:36:46


PHP: Main - Your Source For PHP Tutorials!

Note: This tutorial is a revamped version of my old tutorial (PHP: Including Files).

One of the main reasons a lot of people get into coding PHP, is the ability to include files. This will save a lot of time in the long run, and allow you to update pages much more efficiently. In this tutorial, we will be learning the main four different ways of including files.

<? include("file.php"); ?>
Include{} is the easiest method of including. It does exactly what it says, and simply includes the specified file.

<? include_once("file.php"); ?>
Include_Once{} is a little more advanced. Primarily it does the same as Include{} does, except that it includes the file only once. For example, if you had the script to include file.php and then the same script another 30 times, it would still only include it once.

<? require("file.php"); ?>
Require{} is the same as Include{} except that it will stop the page loading if it cannot load file.php. Require{} will halt the loading of the rest of the page, is the specified file cannot be included for some reason. This is useful if the file your trying to include is a vital part of the page.

<? require_once("file.php"); ?>
Require_Once{} as im sure you have guesses is a mixture of Include_Once{} and Require{}. It will include the file only once, but will halt the loading of the rest of the page, should the file be unloadable.

It is entirely up to you which including method you use. However, most proffesinal programmers will reccomend you use the require function, as pages probably should not display if there is a fatal error on the page as well.

You should also be aware that the file your including does not have to have a .php extenstion. You can include any file, from a .html to a .png should you want to.


|| Portfolio || Facebook || Twitter ||

BBS Signature

Response to Php: Including Files 2007-05-07 10:25:59


Argh. Don't use short tags.


"My software never has bugs. It just develops random features. " - Unknown

[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]

BBS Signature

Response to Php: Including Files 2007-05-07 13:15:05


At 5/7/07 10:25 AM, elbekko wrote: Argh. Don't use short tags.

I agree.

I like the idea of the tutorial, but please re-submit without short tags. Never use short tags when teaching or in an environment where people you don't know will be looking.

There's no saying who has them enabled and who doesn't.