Skip to content

Instantly share code, notes, and snippets.

@Stasonix
Created July 28, 2012 05:56
Show Gist options
  • Save Stasonix/3192011 to your computer and use it in GitHub Desktop.
Save Stasonix/3192011 to your computer and use it in GitHub Desktop.
PHP Украинский ip ( функция проверки )
<?php
/* функция проверки является ли пользователь из Украины
* @param (string) ip - ip адрес пользователя
* @return (bool) - если пользователь из Украины вернет TRUE, если нет, то FALSE
*/
function ipUA($uIp)
{
$bytes = explode(".",$uIp);
$bytes[0] = (int) $bytes[0];
$bytes[1] = (int) $bytes[1];
$bytes[2] = (int) $bytes[2];
$bytes[3] = (int) $bytes[3];
// 62.149.0.0 - 62.149.31.255
if ($bytes[0]==62 and $bytes[1]==149 and $bytes[2]<=31 and $bytes[3]<=255)
{
return TRUE;
}
// 62.80.160.0 - 62.80.191.255
elseif ($bytes[0]==62 and $bytes[1]==80 and ($bytes[2]>=160 and $bytes[2]<=191) and $bytes[3]<=255)
{
return TRUE;
}
// 62.64.64.0 - 62.64.127.255
elseif ($bytes[0]==62 and $bytes[1]==64 and ($bytes[2]>=64 and $bytes[2]<=127) and $bytes[3]<=255)
{
return TRUE;
}
// 62.32.55.0 - 62.32.55.255
elseif ($bytes[0]==62 and $bytes[1]==32 and $bytes[2]==55 and $bytes[3]<=255)
{
return TRUE;
}
// 62.32.63.232 - 62.32.63.239
elseif ($bytes[0]==62 and $bytes[1]==32 and $bytes[2]==63 and ($bytes[3]>=232 and $bytes[3]<=239))
{
return TRUE;
}
else
{
return FALSE;
}
}
?>
@Stasonix
Copy link
Author

Пример использования:

$ip = "62.32.63.239";

if (ipUA($ip))
{

echo "UKRAINE";

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment