http://hola.org/
Y darle a comenzar:
Más información en:
https://viatea.es/tutoriales/acceder-web-otro-pais/
Mostrando entradas con la etiqueta IPs. Mostrar todas las entradas
Mostrando entradas con la etiqueta IPs. Mostrar todas las entradas
IP: Obtener el country_code de un país a partir de una IP (sin APIs de pago)
function getIPUser() {
$ip = 0;
if (!empty($_SERVER['HTTP_CLIENT_IP']) && (ip2long($_SERVER['HTTP_CLIENT_IP']) != -1)) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ipList = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
if ($ip) {
array_unshift($ipList, $ip);
$ip = 0;
}
foreach ($ipList as $v) {
$v = trim($v);
if (!eregi('^(192\.168|172\.16|10|224|240|127|0)\.', $v) && (ip2long($v) != -1)) {
return $v;
}
}
}
return $ip ? $ip : $_SERVER['REMOTE_ADDR'];
}
function esArgentina() {
$retorno = false;
$ip = getIPUser();
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
if ($details->country == "AR") { // argentina
$retorno = true;
}
return $retorno;
}
IP: Obtener todos los datos del visitante a partir de la IP
Hay que registrarse en:
https://ipdata.co/registration.html
Te mandarán a tu email una api_key.
Es una api gratis pero a partir de cierto número de llamadas ya se bloquea durante unas horas. Para que eso no pase:
https://ipdata.co/pricing.html
https://ipdata.co/registration.html
Te mandarán a tu email una api_key.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.ipdata.co?api-key=d27ee727aab18f015fa2b085959c398c0c5a40dc7558db745b1605fb"); // manda nuestra IP
// Si queremos pasarle nosotros una IP en concreta sería:
// curl_setopt($ch, CURLOPT_URL, "https://api.ipdata.co/213.229.183.42");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json"
));
$json = curl_exec($ch);
curl_close($ch);
$arr = json_decode($json);
print_r($arr);
echo "<hr>";
echo $arr->country_code;
Es una api gratis pero a partir de cierto número de llamadas ya se bloquea durante unas horas. Para que eso no pase:
https://ipdata.co/pricing.html
IPs: Banear una IP
function get_ip_real_visitante() {
if (isset($_SERVER["HTTP_CLIENT_IP"])) {
return $_SERVER["HTTP_CLIENT_IP"];
}
elseif (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {
return $_SERVER["HTTP_X_FORWARDED_FOR"];
}
elseif (isset($_SERVER["HTTP_X_FORWARDED"])) {
return $_SERVER["HTTP_X_FORWARDED"];
}
elseif (isset($_SERVER["HTTP_FORWARDED_FOR"])) {
return $_SERVER["HTTP_FORWARDED_FOR"];
}
elseif (isset($_SERVER["HTTP_FORWARDED"])) {
return $_SERVER["HTTP_FORWARDED"];
}
else {
return $_SERVER["REMOTE_ADDR"];
}
}
$ip_visitante = get_ip_real_visitante();
if ((isset($_SESSION[$ip_visitante])) && ($_SESSION[$ip_visitante] > 3)) {
echo "IP Baneada";
sleep(3);
exit;
}
if ($totobien) {
...
}
else {
$_SESSION[$ip_visitante]++;
}
Suscribirse a:
Entradas (Atom)
