Thursday, January 22, 2009

Including code from other files

The ability to include code from other files is a core part of PHP. All that’s necessary is to
use one of PHP’s include commands and tell the server where to find the file.

PHP has four commands that can be used to include code from an external file, namely:
include()
include_once()
require()
require_once()

They all do basically the same thing, so why have four?

include() is the only command you need. The fundamental difference is that
include() attempts to continue processing a script, even if the include file is missing,
whereas require() is used in the sense of mandatory: if the file is missing, the PHP
engine stops processing and throws a fatal error.

The purpose of include_once() and require_once() is to ensure that the external file doesn’t reset any variables that may have been assigned a new value elsewhere. Since you normally include an external file only once in a script, these commands are rarely necessary. However, using them does no harm.

PHP’s built-in superglobal arrays

The main superglobal arrays

$_POST: This contains values sent through the post method. where you'll use it to send the content of an online feedback form by email to your inbox.
$_GET: This contains values sent through a URL query string. You'll use it frequently to pass information to a database.
$_SERVER: This contains information stored by the web server, such as filename,
pathname, hostname, etc.
$_FILES: This contains details of file uploads
$_SESSION: This stores information that you want to preserve so that it's available to other pages. It's used to create a simple login system

0 comments:

Post a Comment