protected function CheckIP(){
    $ch = curl_init();
    $timeout = 5;
    $ip = $_SERVER['HTTP_HOST'];
    $url = "http://ip-api.com/json/{$ip}?fields=country";
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $fileContents = curl_exec($ch);
    curl_close($ch);
    $fileContents = json_decode($fileContents, true);
    if($fileContents["country"] == 'Taiwan') show_404();
}

第三方ip-api : https://ip-api.com/docs/api:json

創作者介紹
創作者 摸魚一群人 的頭像
moyunhost

摸魚一群人

moyunhost 發表在 痞客邦 留言(0) 人氣( 1 )