Development

/plugins/sfIpGeolocHelperPlugin/lib/helper/sfIpGeolocHelper.php

You must first sign up to be able to contribute.

root/plugins/sfIpGeolocHelperPlugin/lib/helper/sfIpGeolocHelper.php

Revision 17326, 1.0 kB (checked in by lombardot, 4 years ago)

[sfIpGeolocHelperPlugin] import version 1.0.1

Line 
1 <?php
2
3 function getCoutryByIp($ip=null){
4     if(is_null($ip))
5         $ip=$_SERVER['REMOTE_ADDR'];
6     $ip=long2ip(ip2long($ip));//nettoie l'adresse
7     //SELECT ip2country.IP_FROM, ip2country.IP_TO, ip2country.COUNTRY_CODE2, ip2country.COUNTRY_CODE3, ip2country.COUNTRY_NAME FROM ip2country
8     //WHERE ip2country.IP_FROM<='inet_aton(\"82.243.37.107\")'
9     //AND ip2country.IP_TO>='inet_aton(\"82.243.37.107\")' LIMIT 1
10     $c=new Criteria();
11     $c->add(ip2countryPeer::IP_FROM,inet_aton($ip),Criteria::LESS_EQUAL);
12     $c->add(ip2countryPeer::IP_TO,inet_aton($ip),Criteria::GREATER_EQUAL);
13     $ip2country=ip2countryPeer::doSelectOne($c);
14     
15     if(!$ip2country){
16         return false;
17     }else{
18         $c=new Criteria();
19         $c->add(countryPeer::ISO,$ip2country->getCountryCode2());
20         $country=countryPeer::doSelectOne($c);
21         if(!$country){
22             return false;
23         }
24     }
25     return $country;
26 }
27
28 function inet_aton($ip){
29     $ip=explode('.',$ip);
30     //return 2130706433;
31     return $ip[0]*pow(256,3)+$ip[1]*pow(256,2)+$ip[2]*pow(256,1)+$ip[3];
32 }
33
34
35 ?>
Note: See TracBrowser for help on using the browser.