# defender-security/3.1.0/src/extra/geoip.php

Defender Security – Malware Scanner, Login Security &amp; Firewall, version 3.1.0. 40 lines.

- Page: https://pluginprobe.com/plugins/defender-security/3.1.0/code/src/extra/geoip.php
- Raw: https://pluginprobe.com/plugins/defender-security/3.1.0/raw/src/extra/geoip.php
- Modified: 2021-09-27T07:37:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/defender-security/3.1.0/code/src/extra/geoip.php#L10-L20`.

```php
<?php
/**
 * Author: Hoang Ngo
 */

namespace WP_Defender\Extra;

use MaxMind\Db\Reader;

class GeoIp {
	/**
	 * @var \GeoIp2\Database\Reader
	 */
	protected $provider;

	public function __construct( $dbPath, $type = 'maxmind' ) {
		$this->provider = new Reader( $dbPath );
	}

	/**
	 * @param $ip
	 *
	 * @return array|bool
	 * @throws Reader\InvalidDatabaseException
	 */
	public function ip_to_country( $ip ) {
		$info = $this->provider->get( $ip );
		if ( empty( $info['country'] ) ) {
			return false;
		}

		$country = array(
			'iso'  => $info['country']['iso_code'],
			'name' => $info['country']['names']['en']
		);

		return $country;
	}
}

```
