Is there any way of adjusting the code below, to also allow a static IP that isn’t within the allowed countries please?
$config['redirect_to']='http://www.websiteaddress.com/'; //redirection url for visitors from not allowed countries
$config['allowed_countries']='at,be,ch,de,dk,es,eu,fi,fr,gb,gg,gi,gr,ie,im,it,je,my,nl,no,pt,se,tr,tz,us'; //allowed countries codes
There are several options, but it really depends on how you’re using the $config[‘allowed_countries’] variable. Are you just exploding it and then comparing it to something grabbed from $_SERVER, for instance? You could always just add the IP to the end of that list and use an extra condition in your check:
// assumed $visitorCountry and $allowedStaticIps are set already
$allowed = explode(',', $config['allowed_countries']);
if (!in_array($visitorCountry, $allowed) && !in_array($allowedStaticIps, $allowed)) {
header("Location: $config['redirect_to']");
}
But that could get messy depending on how you extend this further. Personally I would just have the static IPs saved in a separate variable and do a check there too.