11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 3 • <strong>PHP</strong> BASICSwww.it-ebooks.infoincluded file can be parsed by passing the necessary key/value pairs as would be done in a GET request,like this:include "http://www.wjgilmore.com/index.html?background=blue";Ensuring a File Is Included Only OnceThe include_once() function has the same purpose as include() except that it first verifies whether thefile has already been included. Its prototype follows:include_once (filename)If a file has already been included, include_once() will not execute. Otherwise, it will include the fileas necessary. Other than this difference, include_once() operates in exactly the same way as include().The same quirk pertinent to enclosing include() within conditional statements also applies toinclude_once().Requiring a FileFor the most part, require() operates like include(), including a template into the file in which therequire() call is located. Its prototype follows:require (filename)However, there are two important differences between require() and include(). First, the file willbe included in the script in which the require() construct appears, regardless of where require() islocated. For instance, if require() is placed within an if statement that evaluates to false, the file wouldbe included anyway.■ Tip A URL can be used with require() only if allow_url_fopen is enabled, which by default it is.The second important difference is that script execution will stop if a require() fails, whereas it maycontinue in the case of an include(). One possible explanation for the failure of a require() statement isan incorrectly referenced target path.Ensuring a File Is Required Only OnceAs your site grows, you may find yourself redundantly including certain files. Although this might notalways be a problem, sometimes you will not want modified variables in the included file to beoverwritten by a later inclusion of the same file. Another problem that arises is the clashing of functionnames should they exist in the inclusion file. You can solve these problems with the require_once()function. Its prototype follows:require_once (filename)88

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!