Development

sfIp2Country

You must first sign up to be able to contribute.

Version 3 (modified by markchicobaby, 10 years ago)
--

Ip-to-Country Plug-In

The sfIp2Country helps getting the country name and the country ISO code from the visitor IP address.
It is using foreign databases for Ip2Country conversions.
The default database used is: whois.lacnic.net. However, you can change it to meet your needs.

Maintainer

Please report all bugs to Fourat Zouari <fourat[at]gmail[dot]com> (loca|host on IRC)

Licence

For full copyright and license information, please view the LICENSE file that is distributed with this source code.

Installation

  • Install the plugin

  $ symfony plugin-install http://plugins.symfony-project.com/sfIp2Country

  • Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's plugins/ directory

  • Clear the cache

  $ symfony cc

Usage

To get the country code:

<?php echo ip2Country::getInstance()->getCountryCode();?>

This will echo:

TN

If the country was Tunisia.
See ISO codes for more informations.
It will return null if the IP was not retrieved on the current database.
You can force it to check for a static IP and not to auto-detect the visitor's IP, here's an example:

<?php echo ip2Country::getInstance('193.95.66.10')->getCountryCode();?>

Available methods

  • getProvider(): Returns the database provider URI used to fetch country informations, whois.lacnic.net is used by default.
  • getRemoteAddress(): Returns the visitor remote IP address.
  • getCountryName(): Returns the ISO country name.
  • getCountryCode(): Returns the ISO country code.
  • setProvider($v): Set the provider URI to fetch country informations.
  • setRemoteAddress($v): Force the visitor remote IP address, this can be done in a more flexible way:
       <?php echo ip2Country::getInstance($v)->getCountryCode();?>
    
    Where $v is the forced visitor remote IP address.

Todo

  • Caching.
  • Error handling/logging for foreign socket connections.
  • Helpers to provide flags.

Changelog

2007-11-10 | 0.1

  • fourat: Initial release

Attachments