cvs: peardoc / global.ent /en/package/networking net-geoip.xml /en/package/networking/net-geoip getinstance.xml lookupcountrycode.xml
lookupcountryname.xml lookuplocation.xml lookuporg.xml lookupregion.xml

From: Date: Mon, 05 Sep 2005 18:53:46 +0000
Subject: cvs: peardoc / global.ent /en/package/networking net-geoip.xml /en/package/networking/net-geoip getinstance.xml lookupcountrycode.xml
lookupcountryname.xml lookuplocation.xml lookuporg.xml lookupregion.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-6729@lists.php.net to get a copy of this message
mj Mon Sep 5 14:53:46 2005 EDT Added files: /peardoc/en/package/networking net-geoip.xml /peardoc/en/package/networking/net-geoip getinstance.xml lookupcountrycode.xml lookupcountryname.xml lookuplocation.xml lookuporg.xml lookupregion.xml Modified files: /peardoc global.ent Log: * Added documentation for Net_GeoIP

http://cvs.php.net/diff.php/peardoc/global.ent?r1=1.52&r2=1.53&ty=u Index: peardoc/global.ent diff -u peardoc/global.ent:1.52 peardoc/global.ent:1.53 --- peardoc/global.ent:1.52 Sat Aug 13 07:37:27 2005 +++ peardoc/global.ent Mon Sep 5 14:53:46 2005 @@ -1,6 +1,6 @@ <!-- -*- SGML -*- - $Id: global.ent,v 1.52 2005/08/13 11:37:27 lsmith Exp $ + $Id: global.ent,v 1.53 2005/09/05 18:53:46 mj Exp $ Contains global "macros" for all the XML documents. @@ -61,6 +61,9 @@ <!ENTITY url.oreilly 'http://www.oreilly.com/'> <!ENTITY url.man.index 'http://unixhelp.ed.ac.uk/alphabetical/index.html'> <!ENTITY url.man.freebsd.index 'http://www.freebsd.org/cgi/man.cgi'> +<!ENTITY url.maxmind 'http://maxmind.com/'> +<!ENTITY url.maxmind.db.free 'http://www.maxmind.com/app/geoip_country'> +<!ENTITY url.maxmind.db.nonfree 'http://www.maxmind.com/app/products'> <!ENTITY url.meerkat 'http://meerkat.oreillynet.com/'> <!ENTITY url.pecl 'http://pecl.php.net/'> <!ENTITY url.phing 'http://phing.info/'> http://cvs.php.net/co.php/peardoc/en/package/networking/net-geoip.xml?r=1.1&p=1 Index: peardoc/en/package/networking/net-geoip.xml +++ peardoc/en/package/networking/net-geoip.xml <!-- $Revision: 1.1 $ --> <sect1 id="package.networking.net-geoip"> <title>Net_GeoIP</title> <para> Library to perform geo-location lookups of IP addresses. </para> <para> This package is built on top of <ulink url="&url.maxmind;">MaxMind</ulink>'s GeoIP databases to accurately determine the geographic location of an IP address. MaxMind offers both <ulink url="&url.maxmind.db.free;">free</ulink> and <ulink url="&url.maxmind.db.nonfree;">non-free database</ulink>. Please refer to their website for specific instructures on obtaining both database types. </para> &package.networking.net-geoip.getinstance; &package.networking.net-geoip.lookupcountryname; &package.networking.net-geoip.lookupcountrycode; &package.networking.net-geoip.lookupregion; &package.networking.net-geoip.lookuplocation; &package.networking.net-geoip.lookuporg; </sect1> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 --> http://cvs.php.net/co.php/peardoc/en/package/networking/net-geoip/getinstance.xml?r=1.1&p=1 Index: peardoc/en/package/networking/net-geoip/getinstance.xml +++ peardoc/en/package/networking/net-geoip/getinstance.xml <!-- $Revision: 1.1 $ --> <refentry id="package.networking.net-geoip.getinstance"> <refnamediv> <refname>Net_GeoIP::getInstance()</refname> <refpurpose> method to get an instance and avoid re-parsing the database </refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once "Net/GeoIP.php"; </funcsynopsisinfo> <funcprototype> <funcdef>object <function>getInstance()</function></funcdef> <paramdef> string <parameter>$filename</parameter> [, int <parameter>$flags</parameter>] </paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-geoip.getinstance.desc"> &title.desc; <para> This method is an implementation of the so-called singleton pattern and is the preferred way to create instances of <classname>Net_GeoIP</classname>. </para> <example> <title> Creating an instance of <classname>Net_GeoIP</classname> </title> <programlisting role="php"> require_once "Net/GeoIP.php"; $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat", Net_GeoIP::SHARED_MEMORY); </programlisting> </example> <refsect2> <title>Multiple Instances</title> <para> If you want to use multiple databases in one application, you will need to create an instance of <classname>Net_GeoIP</classname> for each database. Using the singleton <function>getInstance</function> method will make sure that at any given point exactly one object for each database exists, which saves on overhead of setting up database segments. </para> </refsect2> </refsect1> <refsect1 id="package.networking.net-geoip.getinstance.param"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $filename</parameter> - Name of (and path to) the database file </para> </listitem> <listitem> <para> <parameter>int $flags</parameter> - Flags that control the class behaviour. This parameter can be one of the following class constants: <itemizedlist> <listitem> <para> <constant>Net_GeoIp::SHARED_MEMORY</constant> - use SHMOP to share a database among multiple PHP instances. </para> <note> <para> Only one <classname>Net_GeoIP</classname> instance can use shared memory at a time. </para> <para> If you are using <constant>Net_GeoIP::SHARED_MEMORY</constant> (shmop) you can only use <constant>Net_GeoIP::SHARED_MEMORY</constant> for one (1) instance (i.e. for one database). Any subsequent attempts to instantiate using <constant>SHARED_MEMORY</constant> will read the same shared memory block already initialized, and therefore will cause problems since the expected database format won't match the database in the shared memory block. </para> <para> Note that there is no easy way to flag <quote>nice errors</quote> to prevent attempts to create new instances using <constant>Net_GeoIP::SHARED_MEMORY</constant> flag and it is also not posible (in a safe way) to allow new instances to overwrite the shared memory block. </para> <para> In short, is you are using multiple databases, use the <constant>Net_GeoIP::SHARED_MEMORY</constant> flag with care. </para> </note> </listitem> <listitem> <para> <constant>Net_GeoIp::MEMORY_CACHE</constant> - store the full contents of the database in memory for current script. </para> <para> This is useful if you access the database several times in a script. </para> </listitem> <listitem> <para> <constant>Net_GeoIp::STANDARD</constant> - standard no-cache version. This is also the default value if this parameter is ommitted. </para> </listitem> </itemizedlist> </para> </listitem> </itemizedlist> </para> </refsect1> </refentry> http://cvs.php.net/co.php/peardoc/en/package/networking/net-geoip/lookupcountrycode.xml?r=1.1&p=1 Index: peardoc/en/package/networking/net-geoip/lookupcountrycode.xml +++ peardoc/en/package/networking/net-geoip/lookupcountrycode.xml <refentry id="package.networking.net-geoip.lookupcountrycode"> <refnamediv> <refname>Net_GeoIP::lookupCountryCode()</refname> <refpurpose> returns 2-letter country code (e.g. <quote>CA</quote>) for specified IP address </refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once "Net/GeoIP.php"; </funcsynopsisinfo> <funcprototype> <funcdef>string <function>lookupCountryCode()</function></funcdef> <paramdef> string <parameter>$addr</parameter> </paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-geoip.lookupcountrycode.desc"> &title.desc; <para> This method returns the 2-letter country code for the given IP address. It works with both the free and the non-free databases. </para> <example> <title> Looking up the country code </title> <programlisting role="php"> require_once "Net/GeoIP.php"; $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat"); try { echo $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']); } catch (Exception $e) { // Handle exception } </programlisting> </example> </refsect1> <refsect1 id="package.networking.net-geoip.lookupcountrycode.param"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $addr</parameter> - IP address </para> <note> <para> Hostnames are not supported. <link linkend="package.networking.net-geoip.hostnames">More information</link>. </para> </note> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-geoip.lookupcountrycode.throws"> &title.throws; <para> This method throws an exception if the IP address is invalid or if the database type is incorrect. </para> </refsect1> </refentry> http://cvs.php.net/co.php/peardoc/en/package/networking/net-geoip/lookupcountryname.xml?r=1.1&p=1 Index: peardoc/en/package/networking/net-geoip/lookupcountryname.xml +++ peardoc/en/package/networking/net-geoip/lookupcountryname.xml <refentry id="package.networking.net-geoip.lookupcountryname"> <refnamediv> <refname>Net_GeoIP::lookupCountryName()</refname> <refpurpose> returns full country name for specified IP address </refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once "Net/GeoIP.php"; </funcsynopsisinfo> <funcprototype> <funcdef>string <function>lookupCountryName()</function></funcdef> <paramdef> string <parameter>$addr</parameter> </paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-geoip.lookupcountryname.desc"> &title.desc; <para> This method returns the full country name for the given IP address. It works with both the free and the non-free databases. </para> <example> <title> Looking up the country name </title> <programlisting role="php"> require_once "Net/GeoIP.php"; $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat"); try { echo $geoip->lookupCountryName($_SERVER['REMOTE_ADDR']); } catch (Exception $e) { // Handle exception } </programlisting> </example> </refsect1> <refsect1 id="package.networking.net-geoip.lookupcountryname.param"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $addr</parameter> - IP address </para> <note id="package.networking.net-geoip.hostnames"> <title>Lookups on Hostnames</title> <para> Note that this PHP API does NOT support lookups on hostnames. This is so that the public API can be kept simple and so that the lookup functions don't need to try name lookups if IP lookup fails (which would be the only way to keep the API simple and support name-based lookups). </para> <para> If you do not know the IP address, you can convert an name to IP very simply using PHP native functions or other libraries: </para> <programlisting role="php"> $geoip->lookupCountryName(gethostbyname("example.com")); </programlisting> <para> Or, if you don't know whether an address is a name or IP address, use application-level logic: </para> <programlisting role="php"> if (ip2long($ip_or_name) === false) { $ip = gethostbyname($ip_or_name); } else { $ip = $ip_or_name; } $country = $geoip->lookupCountryName($ip); </programlisting> </note> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-geoip.lookupcountryname.throws"> &title.throws; <para> This method sthrow an exception if the IP address is invalid or if the database type is incorrect. </para> </refsect1> </refentry> http://cvs.php.net/co.php/peardoc/en/package/networking/net-geoip/lookuplocation.xml?r=1.1&p=1 Index: peardoc/en/package/networking/net-geoip/lookuplocation.xml +++ peardoc/en/package/networking/net-geoip/lookuplocation.xml <refentry id="package.networking.net-geoip.lookuplocation"> <refnamediv> <refname>Net_GeoIP::lookupLocation()</refname> <refpurpose> returns the location record for specified IP address </refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once "Net/GeoIP.php"; </funcsynopsisinfo> <funcprototype> <funcdef>object <function>lookupLocation()</function></funcdef> <paramdef> string <parameter>$addr</parameter> </paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-geoip.lookuplocation.desc"> &title.desc; <para> This method returns an instance of <classname>Net_GeoIP_Location</classname> for the specified IP address. It works only with a non-free City database. </para> <example> <title> Looking up the location record </title> <programlisting role="php"> require_once "Net/GeoIP.php"; $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat"); try { $location = $geoip->lookupLocation($_SERVER['REMOTE_ADDR']); var_dump($location); printf("City: %s, %s\nLatitude: %s, Longitude: %s\n", $location->city, $location->region, $location->latitude, $location->longitude); } catch (Exception $e) { // Handle exception } </programlisting> </example> </refsect1> <refsect1 id="package.networking.net-geoip.lookuplocation.param"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $addr</parameter> - IP address </para> <note> <para> Hostnames are not supported. <link linkend="package.networking.net-geoip.hostnames">More information</link>. </para> </note> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-geoip.lookuplocation.throws"> &title.throws; <para> This method throws an exception if the IP address is invalid. </para> </refsect1> </refentry> http://cvs.php.net/co.php/peardoc/en/package/networking/net-geoip/lookuporg.xml?r=1.1&p=1 Index: peardoc/en/package/networking/net-geoip/lookuporg.xml +++ peardoc/en/package/networking/net-geoip/lookuporg.xml <refentry id="package.networking.net-geoip.lookuporg"> <refnamediv> <refname>Net_GeoIP::lookupOrg()</refname> <refpurpose> returns the name of the organization or ISP for the given IP address. </refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once "Net/GeoIP.php"; </funcsynopsisinfo> <funcprototype> <funcdef>string <function>lookupOrg()</function></funcdef> <paramdef> string <parameter>$addr</parameter> </paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-geoip.lookuporg.desc"> &title.desc; <para> This method returns the name of the organization or of the ISP which has registered the IP address range that contains the specified IP address. It works only with a non-free Organization/ISP database. </para> <example> <title> Looking up organization name </title> <programlisting role="php"> require_once "Net/GeoIP.php"; $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat"); try { echo $geoip->lookupOrg($_SERVER['REMOTE_ADDR']); } catch (Exception $e) { // Handle exception } </programlisting> </example> </refsect1> <refsect1 id="package.networking.net-geoip.lookuporg.param"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $addr</parameter> - IP address </para> <note> <para> Hostnames are not supported. <link linkend="package.networking.net-geoip.hostnames">More information</link>. </para> </note> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-geoip.lookuporg.throws"> &title.throws; <para> This method throws an exception if the IP address is invalid or the database type is wrong. </para> </refsect1> </refentry> http://cvs.php.net/co.php/peardoc/en/package/networking/net-geoip/lookupregion.xml?r=1.1&p=1 Index: peardoc/en/package/networking/net-geoip/lookupregion.xml +++ peardoc/en/package/networking/net-geoip/lookupregion.xml <refentry id="package.networking.net-geoip.lookupregion"> <refnamediv> <refname>Net_GeoIP::lookupRegion()</refname> <refpurpose> returns the region for given IP address. </refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> <funcsynopsisinfo> require_once "Net/GeoIP.php"; </funcsynopsisinfo> <funcprototype> <funcdef>array <function>lookupRegion()</function></funcdef> <paramdef> string <parameter>$addr</parameter> </paramdef> </funcprototype> </funcsynopsis> </refsynopsisdiv> <refsect1 id="package.networking.net-geoip.lookupregion.desc"> &title.desc; <para> This method returns an array containing the country code and the region for the specified IP address. It works only with a non-free Region database. </para> <example> <title> Looking up the region </title> <programlisting role="php"> require_once "Net/GeoIP.php"; $geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat"); try { list($country_code, $region) = $geoip->lookupRegion($_SERVER['REMOTE_ADDR']); } catch (Exception $e) { // Handle exception } </programlisting> </example> </refsect1> <refsect1 id="package.networking.net-geoip.lookupregion.param"> &title.param; <para> <itemizedlist> <listitem> <para> <parameter>string $addr</parameter> - IP address </para> <note> <para> Hostnames are not supported. <link linkend="package.networking.net-geoip.hostnames">More information</link>. </para> </note> </listitem> </itemizedlist> </para> </refsect1> <refsect1 id="package.networking.net-geoip.lookupregion.throws"> &title.throws; <para> This method throws an exception if the IP address is invalid. </para> </refsect1> </refentry>
« previous php.pear.doc (#6729) next »