<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class GeoBlock
{
    public function checkCountry()
    {
        $ip = $_SERVER['REMOTE_ADDR'];

        $data = @json_decode(file_get_contents("http://ip-api.com/json/$ip"));

        if (!$data) {
            return; // API fail ho to website chalne do ya apni policy ke hisab se block kar do
        }

        // if (!in_array($data->countryCode, ['IN', 'US'])) {
        if (!in_array($data->countryCode, ['IN', 'US'])) {
            header("HTTP/1.1 403 Forbidden");
            exit('Access Denied');
        }
    }
}