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

Defender Security – Malware Scanner, Login Security &amp; Firewall, version 5.4.0. 38 lines.

- Page: https://pluginprobe.com/plugins/defender-security/5.4.0/code/src/extra/geoip.php
- Raw: https://pluginprobe.com/plugins/defender-security/5.4.0/raw/src/extra/geoip.php
- Modified: 2024-07-15T18:05:32+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/5.4.0/code/src/extra/geoip.php#L10-L20`.

```php
<?php
/**
 * @package WP_Defender\Extra
 */

namespace WP_Defender\Extra;

use MaxMind\Db\Reader;

class GeoIp {
	/**
	 * @var \GeoIp2\Database\Reader
	 */
	protected $provider;

	public function __construct( $dbPath ) {
		$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;
		}

		return array(
			'iso'  => $info['country']['iso_code'],
			'name' => $info['country']['names']['en'],
		);
	}
}

```
