HOME  |  WEB DESIGN  |  COMPUTING  |  GRAPHICS/PHOTOS  |  MUSIC
Web Sites Web Design Web Technology Panoramic Earth School Web Sites Summer Web Sites DLib PHP Library Introduction Download Installation Database Examples 1 Database Examples 2 HTML Examples HtmlPage Examples DLib PHP Library API

Installation

DLib PHP Library

Note that the instructions on this and subsequent pages assume that you are fully conversant with normal PHP programming methods. If this is not the case then pick up one of the many PHP books that are currently available (a new one seems to come out every week!).

Unzip the downloaded file into an area of your site that is OUTSIDE of the normal publicly accessible area. For example, you may have the following directories on a Unix/Linux server running Apache:

/var/www/htdocs   <-- where the document root points
/var/www/cgi-bin  <-- where CGI programs live

You could put the library at the same level:

/var/www/dlib5     <-- library files

For the PHP pages inside htdocs you will need to add a single include file that will allow those pages access to the library. Create a file include.php with the following code and put it in htdocs:

<?php

if (strpos ($_SERVER ['SCRIPT_NAME'], "include.php") !== false)
  die ("Illegal access");

ini_set ("include_path", ".:/var/www/dlib5");
include_once "lib.php";

?>

The file is doing three things:

  1. making sure that it is not being run directly (and dieing if so);
  2. setting the include path to the current directory (the '.' dot) as well as to where the library has been installed;
  3. attempting to call the main library include file (lib.php) which, itself, will include all the other files in the library.

Notes:

  • If you are running several different web sites off a single server (e.g. you may be using Apache's Virtual Name Servers) then only one instance of the library is necessary, which makes upgrading very simple!
  • Any other PHP file on your web site that needs to access the library only needs to include the include.php file.
  • If you are going to create a set of other PHP files/functions that will be common to your entire web site then you could also place those files in their own directory outside the document root such as /var/www/commonphp and then add another include_once call within include.php to gain access to those as well. You would also need to add their directory to the ini_set function call.
  • Users running on a Windows system will need to modify the ini_set statement to reflect that system's directory separator and volume differences.)

Here's an example include.php to illustrate some of the above. This time it's for Windows and assumes that you have installed the library within the normal Apache 2 location and have added some extra code in commonphp, and the main include file for your code is called mystuff.php:

<?php

if (strpos ($_SERVER ['SCRIPT_NAME'], "include.php") !== false)
  die ("Illegal access");

ini_set ("include_path", ".;C:\Program Files\Apache Group\Apache2\dlib5;C:\Program Files\Apache Group\Apache2\commonphp");

include_once "lib.php";
include_once "mystuff.php";

?>

The final example shows how you can use the same include.php file to handle a local development server on Windows and a live server that uses Unix/Linux. This interrogates the host it is running on to figure out which type of format it should be using which means that separate files need not be created for running the same code on different operating systems. Note that we also set a variable $live which may come in useful in other parts of the system for allowing separate functions or code to run on the local development and live servers, and we set a value in $dbTablePrefix which prefixes all the tables used with, in this case, xyz_. This is useful when you are running several sites on one physical database - a common restriction with some hosting services - so that you can easily separate each group of tables from each other.

<?php

if (strpos ($_SERVER ['SCRIPT_NAME'], "include.php") !== false)
  die ("Illegal access");

$host = $_SERVER ['HTTP_HOST'];

switch ($host)
{
  case "www.somewhere.com" :
    ini_set ("include_path", ".:/var/www/dlib5:/var/www/commonphp");
    $live = true;
    break;

  default :
    ini_set ("include_path", ".;C:\Program Files\Apache Group\Apache2\dlib5;C:\Program Files\Apache Group\Apache2\commonphp");
    $live = false;
}

$dbTablePrefix = "xyz_";
include_once "lib.php";
include_once "mystuff.php";

?>