简体   繁体   English

根据国家/地区重定向,但如果 IP 被列入白名单,则允许

[英]Redirect based on Country but allow if IP is whitelisted

I have a script that Redirects people from my country and allow all others to stay if not my country.我有一个脚本,可以重定向来自我的国家的人,如果不是我的国家,则允许所有其他人留下。

How can I whitelist my IP address to stay if its from the country which should redirect all?如果我的 IP 地址来自应该重定向所有的国家/地区,我该如何将其列入白名单?

require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
// create a variable for the country code
$var_country_code = $geoplugin->countryCode;
// redirect based on country code:
if ($var_country_code == "BG") {
   header('Location: https://wikipedia.org/');
}
else if ($var_country_code == "E1") {
   header('Location: https://website.xyz/wordpress');

}
?>```

I think you can try to get client IP then check against your IP (if it is STATIC) and if it is TRUE then you may not redirect if not(else) get there location and continue with the rest of your code我认为您可以尝试获取客户端 IP 然后检查您的 IP(如果它是静态的),如果它是 TRUE 那么您可能不会重定向,如果不是(否则)到达那里并继续使用您的代码 Z65E8800B5C68002AADFCZA

if (client_IP == "Your own IP") {
   header('Location: Whatever location you want');
}
else if ($var_country_code == "BG") {
   header('Location: https://wikipedia.org/');
}
else if ($var_country_code == "E1") {
   header('Location: https://pasted.xyz/wordpress');
}

I hope this helps you我希望这可以帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM