Country Detecter Script Help

Started on the old forum in December 2006 · view the original in the archive · old links redirect here

47 replies · 6,897 views · started 19 years ago · 1 min read

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.

15 participants
Guest #1

Can anyone give me Country Detecter Script who can detect users country?

Guest #4

thanx gum,was also looking 4 that!

lamar-wap #5

thanx gum,was also looking 4 that!

i got a different one............ on my site http://fimizone.org

its kinda different..................

thanatos Senior · 261 posts #6

here is one

does this script can be use in rw? i think it's in html format.. does anybody here got the script for wml? tnx

Guest #7

waiting for ans... .is it work with rw?

lamar-wap #8

waiting for ans... .is it work with rw?

yes it does work with rw but you need to add some new fields to your users table................

im still trying mine did not get it working fully yet but i think you can ask munis for help...........................

Guest #11

Thanks GumSlone

thunderwap Developer · 169 posts #12

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!!

Guest #14

how do i get it in fun mobile user profile

GumSlone Administrator Principal · 1,690 posts #15

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

External image (may be gone)

Guest #16

jussst wait im working on that, i'll try to post the codes to make it work on lavalair's script. and also codes to ban the whole country!!

GumSlone Administrator Principal · 1,690 posts #17

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

External image (may be gone)

rukiya Lead · 569 posts #18

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?

GumSlone Administrator Principal · 1,690 posts #19

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

External image (may be gone)

Guest #20

I use database to detect country in main page... and in my portal i made a script which doesnt uses databse... My script also detect users network

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close