How can I display my website in only one city?
The client only wants to be seen in one city all over the world, how can I do that, I would really appreciate your help :)
I did what you told me:
https://i.gyazo.com/5c933886ffd28e8287d803c094574009.png
and it sends me this error:
array ( 'geoplugin_request' => '::1', 'geoplugin_status' => 404, 'geoplugin_credit' => 'Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com.', 'geoplugin_city' => NULL, 'geoplugin_region' => NULL, 'geoplugin_areaCode' => NULL, 'geoplugin_dmaCode' => NULL, 'geoplugin_countryCode' => NULL, 'geoplugin_countryName' => NULL, 'geoplugin_continentCode' => NULL, 'geoplugin_latitude' => NULL, 'geoplugin_longitude' => NULL, 'geoplugin_regionCode' => NULL, 'geoplugin_regionName' => '', 'geoplugin_currencyCode' => NULL, 'geoplugin_currencySymbol' => NULL, 'geoplugin_currencySymbol_UTF8' => '', 'geoplugin_currencyConverter' => '0', )
Updated based on Alfredo Paz's comment
In the case of PHP you could resort to the following:
1) Obtain the IP address of the visitor.
2) Call a geolocation service, in this case http://www.geoplugin.net :
3) Use the values of the obtained object:
4) Assign the city and verify that it is the allowed city
5) Your error page
6) Complete would be something like:
Note: Change the code so that you take the allowed city instead of going through all the cities that can NOT be valid.
Updated to verify the country and city of origin:
I add the code also verifying the country of origin avoiding conflicts of the same city, for example: Venezuela and Spain have a city called Barcelona
In this case, we first verify that the client is in Venezuela and second that it is in the city of Barcelona.
Updated based on Adriá Vilanova's comment
I quote your comment:
1 I add to the accepted answer the way to obtain the ip that has worked for me taking into account proxies, loadbalancers and others:
Note that in the last lines I discard the extra ip added when the request passes through several proxies (it may not be the real ip if it is discarded in the proxy for security reasons, but it is a good approximation).
2 Doing tests in local environments and behind routers, balancers or nat the reported ip will be the local one with which a geoip location will give an error, to correct this we use the following trick:
3 Keep in mind that services like geoplugin are free up to 150/200 requests/queries per minute, this may be acceptable for a website with low to normal traffic, but if a marketing campaign is carried out with a deadline, it is most likely that in the first hours the server receives many simultaneous queries and fails. To avoid the latter you will have to:
a) download your own copy of geolite database
b) install a library to use it. (PHP using composer https://getcomposer.org/ )
c) use the library:
Note: the use of this library may require installing extra php extensions (bcmath or gmp for example)