Country Detecter Script Help
Started on the old forum in December 2006 · view the original in the archive · old links redirect here
TL;DR · summary of 47 replies
- - The script provided by GumSlone works with PHP scripts, including Fun Mobile and Lavalair WML.
- - To reserve one user's $two_letter_country_code data in the database for showing to all users, additional columns need to be added to the MySQL table used for storing user profiles.
- - For detecting country using IP addresses without a database, GumSlone suggested an alternative script available at
- - The thread concluded that some country detection scripts may not accurately detect users' locations due to intermediaries and the need for paid services.
Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.
here is one
Advertise your mobile site for FREE with AdTwirl
thanx gum,was also looking 4 that!
i got a different one............ on my site http://fimizone.org
its kinda different..................
you can see ip to country in my site in user profile External image (may be gone)
Lamar pls post your ip2 country edited script for Lavalair script.I saw it works fine in your fimizone.org..thanks External image (may be gone)
here is one
thanks gum i also want that.but does this works in fun mobile script.
WANT GOOD CHEAP HOSTING WITH 99% UPTIME? THEN PM ME FOR DETAILS!!
how to block a particular country from accessing ur site?
Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!
thanks gum i also want that.but does this works in fun mobile script.
it works with all php scripts, not only with funmobile
Advertise your mobile site for FREE with AdTwirl
Here is another ip to country without database script: http://www.phptutorial.info/iptocountry/the_script.html
and here is a function how to use it:
for iso county 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="unkown";}
return $two_letter_country_code;
}
for country name:
function country_name($two_letter_country_code)
{
include("ip_files/countries.php");
$country_name=$countries[$two_letter_country_code][0];
return $country_name;
}
usage:
$two_letter_country_code=iptocountry($_SERVER['REMOTE_ADDR']);
echo 'County flag: '.country_name($two_letter_country_code);
to show the country flag:
function show_flag($two_letter_country_code)
{
$file_to_check='./ip_flags/'.strtolower($two_letter_country_code).'.gif';
if (file_exists($file_to_check)){
$FLAG= '[img]'.$file_to_check.'[/img]';
}else{
$FLAG= '[img]./ip_flags/noflag.gif[/img]';
}
return $FLAG;
}
usage:
$two_letter_country_code=iptocountry($_SERVER['REMOTE_ADDR']);
echo 'County flag: '.show_flag($two_letter_country_code);
and to ban someone you can use this example:
$two_letter_country_code=iptocountry($_SERVER['REMOTE_ADDR']);
///ZA- South africa; DE -Germany///////
if($two_letter_country_code=='ZA' || $two_letter_country_code=='DE'){
echo '<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card>
We do not provide any services for your country.
</p>
</card>
</wml>';
exit;
}
Advertise your mobile site for FREE with AdTwirl
Here is another ip to country without database script: http://www.phptutorial.info/iptocountry/the_script.html
and here is a function how to use it:
for iso county 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="unkown";} return $two_letter_country_code; }for country name:
function country_name($two_letter_country_code) { include("ip_files/countries.php"); $country_name=$countries[$two_letter_country_code][0]; return $country_name; }usage:
$two_letter_country_code=iptocountry($_SERVER['REMOTE_ADDR']); echo 'County flag: '.country_name($two_letter_country_code);to show the country flag:
function show_flag($two_letter_country_code) { $file_to_check='./ip_flags/'.strtolower($two_letter_country_code).'.gif'; if (file_exists($file_to_check)){ $FLAG= ''.$file_to_check.''; }else{ $FLAG= './ip_flags/noflag.gif'; } return $FLAG; }usage:
$two_letter_country_code=iptocountry($_SERVER['REMOTE_ADDR']); echo 'County flag: '.show_flag($two_letter_country_code);and to ban someone you can use this example:
$two_letter_country_code=iptocountry($_SERVER['REMOTE_ADDR']); ///ZA- South africa; DE -Germany/////// if($two_letter_country_code=='ZA' || $two_letter_country_code=='DE'){ echo '<?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card> We do not provide any services for your country. </p> </card> </wml>'; exit; }
many thanks to Gum,
1 more question,how can i reserve one user's $two_letter_country_code data in that user's profile to show that user's $two_letter_country_code to all user,i mean wt will b mysql table to save n show $two_letter_country_code to all users?
many thanks to Gum, 1 more question,how can i reserve one user's $two_letter_country_code data in that user's profile to show that user's $two_letter_country_code to all user,i mean wt will b mysql table to save n show $two_letter_country_code to all users?
Hmmm, i dont realy understand what do you mean, and i dont know which mysql tables are you using External image (may be gone) so here is very simple example: you have to add the country row to your users table
UPDATE `users` SET `country`='".$two_letter_country_code."' WHERE id='".$user_id."'
and to select users (South africans)
SELECT * FROM `users` WHERE `country`='ZA' LIMIT 0, 10
Advertise your mobile site for FREE with AdTwirl