ip to country
Started on the old forum in July 2018 · view the original in the archive · old links redirect here
http://php.net/manual/en/geoip.setup.php
<?
$countryName = geoip_country_name_by_name($ip);
$countryCode = geoip_country_code_by_name($ip);
print '<img src="flags/'.$countryCode.'.png" alt="'.$countryName.'"/>';
?>
I have a code already, but the problem is it does not identify a flag for certain IPs. This is my code
function iptocountry($ip) {
$numbers = preg_split( "/./", $ip);
include("ip_files/".$numbers[0].".php");
$code=($numbers[0] * 16777216) +($numbers[1] * 65536) + ($numbers[2] * 256) +($numbers[3]);
foreach($ranges as $key => $value){
if($key<=$code){
if($ranges[$key][0]>=$code) {$two_letter_country_code=$ranges[$key][1];break;}
} } if ($two_letter_country_code=="") {$two_letter_country_code="unknown";}
return $two_letter_country_code;
}
Easier way:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$geo = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
$city = $geo['geoplugin_city'];
$region = $geo['geoplugin_region'];
$country = $geo['geoplugin_countryName'];
echo 'City: '.$city.', Region: '.$region.', Country: '.$country.'<br/>';
/*
geoplugin_request
geoplugin_status
geoplugin_credit
geoplugin_city
geoplugin_region
geoplugin_areaCode
geoplugin_dmaCode
geoplugin_countryCode
geoplugin_countryName
geoplugin_continentCode
geoplugin_latitude
geoplugin_longitude
geoplugin_regionName
geoplugin_currencyCode
geoplugin_currencySymbol
geoplugin_currencySymbol_UTF8
geoplugin_currencyConverter
*/
?>
With your function it would be:
function iptocountry($ip)
{
$geo = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$ip));
return $geo['geoplugin_countryCode'];
}
Ok, thanks alot bro! Is there anyway to increase the regular 512 or 1024 kb upload limit in class.upload file? I've tried everything, I've even tried to change it to 2000kb or 2048 kb at it still doesn't show images uploaded that's larger than 1024 kb.
something else
I'm not to sure what the question/problem is but at a guess I would say either you are hitting your allowed upload limit on your server, which can be changed via: .htaccess
php_value memory_limit 30M
php_value upload_max_filesize 30M
php_value post_max_size 100M
or php.ini
memory_limit = 30M
upload_max_filesize = 30M
post_max_size = 100M
However I think that you may also be using GD Library in your class.upload file? In which case you are probably running out of memory (See above how to increase memory imit)
However that being said some hosts don't allow the above to be altered.
If you find that you can't adjust the above and you are working with GD Library then you may want to look at imageMagick as an alternative as this does not count against your memory limit.
To view your limits make a script with the following code in: randomName.php
<?php
phpinfo();
?>
(Note: keep this file hidden/deleted after use as it is useful to hackers)