PhP - 如何阻止除英国之外的所有欧盟国家,并允许所有非欧盟国家?

Rew*_*ind 0 php ip

我想要一个页面来阻止除英国之外的欧盟国家/地区,同时允许所有其他非欧盟国家/地区。我所说的阻止是指我想要另一条消息,例如出现“您所在国家/地区不可用的服务”,而不是正常的页面内容。如何才能做到这一点?

注意:我不想通过阻止这些非英国欧盟国家来影响 google-bot 排名。

编辑:这是 VAT MOSS 的事情,没什么险恶的。

Dim*_*nov 6

您可以使用 geoplugin.net geo API。

    //Get user IP address
        $ip=$_SERVER['REMOTE_ADDR'];
        //Using the API to get information about this IP
         $details = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=$ip"));
    //Using the geoplugin to get the continent for this IP
            $continent=$details->geoplugin_continentCode;
    //And for the country
            $country=$details->geoplugin_countryCode;
    //If continent is Europe
            if($continent==="EU" && $country==="UK" || $continent!="EU"){
 //Do action if country is UK or not from Europe
}else{
      //Do action if country is in Europe , but its not UK      
            }
Run Code Online (Sandbox Code Playgroud)

稍微编辑了一下代码:)