PHP 使用 GeoIP 进行不同国家 ip 测试

    $ip = "67.220.91.30";// USA
    switch (mt_rand(0, 15)) {
        case 0:// India
            $ip = "210.212.145.105";
            break;
        case 1:// Spain
            $ip = "94.127.167.255";
            break;
        case 2:// Canada
            $ip = "204.101.161.159";
            break;
        case 3:// Vietnam
            $ip = "113.190.186.74";
            break;    
        case 4:// Ireland
            $ip = "217.173.208.0";
            break;
        case 5:// German
            $ip = "188.103.19.120";
            break;
        case 6:// Australia
            $ip = "124.171.74.153";
            break;
        case 7:// Japan
            $ip = "133.242.187.207";
            break;
        case 8:// Thailand
            $ip = "113.53.76.59";
            break;
        case 9:// Bhutan
            $ip = "103.245.240.0";
            break;
        case 10:// Hungary
            $ip = "62.165.232.178";
            break;
        case 11:// Philippines
            $ip = "115.85.29.130";
            break;
        case 12:// Cuba
            $ip = "200.5.12.0";
            break;
        case 13:// Brazil
            $ip = "201.83.6.2";
            break;
        case 14:// Pakistan
            $ip = "119.155.26.109";
            break;
        default:// China
            $ip = "223.104.1.3";
    }
    $country_code = geoip_country_code3_by_name($ip); // need install geoip module
    setcookie("country_code", $country_code, time() + 31536000, "/", "test.com"); 

 

posted @ 2018-07-03 14:23  一菲聪天  阅读(584)  评论(0编辑  收藏  举报