Cdn.php in GeoIP API 8.2
File
src/Plugin/GeoLocator/Cdn.php
View source
<?php
namespace Drupal\geoip\Plugin\GeoLocator;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
class Cdn extends GeoLocatorBase implements ContainerFactoryPluginInterface {
public function geolocate($ip_address) {
if ($this
->checkCloudflare()) {
$country_code = $this
->checkCloudflare();
}
elseif ($this
->checkCloudFront()) {
$country_code = $this
->checkCloudFront();
}
elseif ($this
->checkCustomHeader()) {
$country_code = $this
->checkCustomHeader();
}
else {
if ($this->geoIpConfig
->get('debug')) {
$this->logger
->notice($this
->t('Unable to look up %ip_address via CDN header', [
'%ip_address' => $ip_address,
]));
}
return NULL;
}
if ($this->geoIpConfig
->get('debug')) {
$this->logger
->notice($this
->t('Discovered %ip_address via CDN header', [
'%ip_address' => $ip_address,
]));
}
return $country_code;
}
protected function checkCloudflare() {
return !empty($_SERVER['HTTP_CF_IPCOUNTRY']) ? $_SERVER['HTTP_CF_IPCOUNTRY'] : NULL;
}
protected function checkCloudFront() {
return !empty($_SERVER['HTTP_CLOUDFRONT_VIEWER_COUNTRY']) ? $_SERVER['HTTP_CLOUDFRONT_VIEWER_COUNTRY'] : NULL;
}
protected function checkCustomHeader() {
return NULL;
}
}
Classes
Name |
Description |
Cdn |
CDN geolocation provider. |