PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Jillis ter Hove   GeoLocation   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example usage of the class
Class: GeoLocation
Get the location of an IP address with the hostip
Author: By
Last change: Added known error condition for PHP 4 when an internal (192.168, 10.) ip is looked up. Will fix this later.
Date: 16 years ago
Size: 2,733 bytes
 

Contents

Class file image Download
<?php
   
/* PHP 4 N.B.
        This » PECL extension is not bundled with PHP. Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: » http://pecl.php.net/package/domxml.

        In PHP 4 this PECL extensions source can be found in the ext/ directory within the PHP source or at the PECL link above. This extension is only available if PHP was configured with --with-dom[=DIR]. Add --with-dom-xslt[=DIR] to include DOM XSLT support. DIR is the libxslt install directory. Add --with-dom-exslt[=DIR] to include DOM EXSLT support, where DIR is the libexslt install directory.

        Windows users will enable php_domxml.dll inside of php.ini in order to use these functions. In PHP 4 this DLL resides in the extensions/ directory within the PHP Windows binaries download. The DLL for this PECL extension may be downloaded from either the » PHP Downloads page or from » http://pecl4win.php.net/ Also, there is one additional DLL that must be made available to your system's PATH in order for this extension to work. In PHP 4 this is in the dlls/ directory. It's name: For PHP <= 4.2.0, it's libxml2.dll. For PHP >= 4.3.0, it's iconv.dll. And as of PHP 5.0.0, iconv is compiled into your Windows PHP binaries by default so no extra DLL is needed.

        The line extension=php_domxml.dll in php.ini should be ENabled. Without it php4 is without XML support.

    */
   
    /* PHP 5:
        Introduction:
        The DOM extension allows you to operate on XML documents through the DOM API with PHP 5.

        Installation:
        There is no installation needed to use these functions; they are part of the PHP core.

        The line extension=php_domxml.dll in php.ini should be DISabled. It gives funky results in
        my php 5.2 installation.
    */
   
    // Example usage of the GeoLocation class
   
include 'GeoLocation.class.php'; # include for effect
   
    // if you are developing with this script and are 'behind' the server, uncomment the following
    // lines and change to your internal ip-address. This will make the script lookup the external
    // (server's) address instead of the internal address. The script will give an error in PHP 4
    // if an internal ip is looked up.
    /*
    if( $_SERVER['REMOTE_ADDR'] == '192.168.2.1' )
        $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_HOST'];
    */

    // construct an instance (should fire off a http get)
   
$geo = new GeoLocation($_SERVER['REMOTE_ADDR']);
   
// instance now contains (city, country, longitude, lattitude) info
   
echo "$_SERVER[REMOTE_ADDR], $geo->city, $geo->country ($geo->longitude, $geo->latitude)";
?>