You must first sign up to be able to contribute.

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: However, you can change it to meet your needs.


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


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


  • Install the plugin

  $ symfony plugin-install

  • 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


To get the country code:

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

This will echo:


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('')->getCountryCode();?>

Available methods

  • getProvider(): Returns the database provider URI used to fetch country informations, 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.


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


2007-11-10 | 0.1

  • fourat: Initial release