<?php
function getRealIp()
{
    if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
        return trim($_SERVER['HTTP_X_REAL_IP']);
    }
    if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ipList = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        return trim($ipList[0]);
    }
    return $_SERVER['REMOTE_ADDR'];
}
$clientIp = getRealIp();
$api = "https://api.ip.sb/geoip/" . urlencode($clientIp);
$ch = curl_init($api);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 2);
$res = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
$info = json_decode($res, true);

if (empty($err) && !empty($info['country_code']) && $info['country_code'] === 'CN') {
    header("Location: dl.php");
    exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>访问限制</title>
</head>
<body>
<h3>仅中国大陆网络支持下载</h3>
</body>
</html>