I need to use IP Geolocation to show a warning message for visitors from certain locations. I’ve enabled the IP Geolocation service in our site’s Dev instance and I’ve successfully tested WordPress/PHP code which uses the $_SERVER['GEOIP_REGION'] variable. This PHP code is called from the browser using Fetch/POST Javascript code to the “/wp-admin/admin-ajax.php” URL. So far so good.
However, there is a warning in your IP Geolocation documentation that the Edge Caching service can cause IP Geolocation to be unreliable. Is this also true when accessing the GEOIP variables from the PHP $_SERVER object as I’ve described?
The Edge Cache on our live containers shouldn’t be used with GeoIP caching or blocking. The reason is that Edge Cache is executed before the request reaches the server so PHP $_SERVER won’t be read at that point.
Thank you for the response. I’ve done a little research about adding a ‘nonce’ and even a timestamp to the Javascript fetch/POST payload so that the caching server will pass the request on to the PHP/WordPress server instead of using a cached version of the response. Do you think this would work?
I’ve also looked at adding ‘Cache-Control’ and ‘Pragma’ headers to the response to prevent caching (see Cache-Control header - HTTP | MDN). Do you know if Kinsta’s Edge Caching will prevent caching if there are such headers?