Skip to content

Commit

Permalink
Update GeoIp.php
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpsan authored Apr 21, 2018
1 parent 7ce7702 commit 022616b
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions GeoIp.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ public function getInfo($id = null) {
"~(Google|Yahoo|Rambler|Bot|Yandex|Spider|Snoopy|Crawler|Finder|Mail|curl)~i",
$_SERVER['HTTP_USER_AGENT']
);
$geo = !$is_bot ? json_decode(file_get_contents('http://api.sypexgeo.net/json/'), true) : [];
var_dump($geo);
if (!$is_bot) :
$curl = new curl\Curl();
$response = json_decode($curl->get('http://api.sypexgeo.net/json/'));
$response = json_decode($curl->get(self::URL_API . '/json/'));
if (empty($response->ip))
return false;
return $response;
Expand All @@ -109,18 +107,15 @@ public function getInfo($id = null) {
*
* @return array|false
*/
public function getInfoDb() {
public function getInfoDb($id = null) {
$response = new Database(Yii::getAlias('@vendor') . '/ip2location/ip2location-php/databases/IP2LOCATION-LITE-DB1.BIN');
if (!$this->externalIp) :
echo '1';
$result = $response->lookup(Yii::$app->request->userIP);
else :
echo $this->getIp();
$result = $response->lookup($this->getIp());
endif;
if ($result['countryCode'] == 'Invalid IP address.') :
if ($result['countryCode'] == 'Invalid IP address.')
return false;
endif;
return $result;
}

Expand All @@ -130,13 +125,14 @@ public function getInfoDb() {
*/
public function getIp() {
$curl = new curl\Curl();
$response = json_decode($curl->get(self::URL_API . '/json/'));
if ($curl->get(self::URL_API . '/json/')) {
if (empty($response->ip)) {
if (!$this->externalIp) :
return Yii::$app->request->userIP;
else :
$response = json_decode($curl->get(self::URL_API . '/json/'));
if (empty($response->ip))
return false;
}
return $response->ip;
}
endif;
return false;
}
}
Expand Down

0 comments on commit 022616b

Please sign in to comment.