Manage cookies that are used for advertising, such as ad personalization, remarketing, and ad effectiveness analysis.
2.8.19. Detect visitor country in PHP
Every request to the site includes a special header called HTTP_GEOIP_COUNTRY_CODE, which contains the visitor's two-letter country code (ISO 3166). The country is determined based on the visitor's IP address using data from MaxMind GeoLite.
You can retrieve a two-letter country code in PHP using the server variable $_SERVER['HTTP_GEOIP_COUNTRY_CODE']. Here is an example of code to block POST requests from any country except Ukraine:
if ($_SERVER['HTTP_GEOIP_COUNTRY_CODE'] != 'UA' && !empty($_POST)) {
die('Access denied');
}
(2)
Comments
Велике ДЯКУЮ!
if ($_SERVER['HTTP_GEOIP_COUNTRY_CODE'] != 'UA' && !empty($_POST)) {
die('Русский военный корабль ...');
}