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
SiLeNce Developer · 138 posts #42

give me in lavalair sc :?

wizard Senior · 493 posts #43
public function getcountry_uid($uid)
    {
        $DB = new DB;
        $ip = $DB->FetchArray($DB->Query("SELECT IPAdd FROM {$GLOBALS['prefix']}members WHERE ID='".$uid."'"));
        $ip = long2ip(ip2long($ip[0]));
        $res = $DB->Query("SELECT ISO2 FROM {$GLOBALS['prefix']}ips WHERE (StartIP <= inet_aton('".$ip."') AND EndIP >= inet_aton('".$ip."'))");
        if($get = $DB->FetchArray($res))
        {
            $country = $DB->Query("SELECT CountryName FROM {$GLOBALS['prefix']}country WHERE ISO2 = '".$get[0]."'");
            if($name = $DB->FetchArray($country))
            {
                $CountryName = $name[0];
            }else{
                $CountryName = 'Unknown';
            }
        }else{
            $CountryName = 'Unknown';
        }
        return $CountryName;
    }

    public function getcountry()
    {
        $DB = new DB;
        $ip = $this->getip();
        $ip = long2ip(ip2long($ip));
        $res = $DB->Query("SELECT ISO2 FROM {$GLOBALS['prefix']}ips WHERE (StartIP <= inet_aton('".$ip."') AND EndIP >= inet_aton('".$ip."'))");
        if($get = $DB->FetchArray($res))
        {
            $country = $DB->Query("SELECT CountryName FROM {$GLOBALS['prefix']}country WHERE ISO2 = '".$get[0]."'");
            if($name = $DB->FetchArray($country))
            {
                $CountryName = $name[0];
            }else{
                $CountryName = 'Unknown';
            }
        }else{
            $CountryName = 'Unknown';
        }
        return $CountryName;
    }
    
    public function getcountryflag($country)
    {
        $DB = new DB;
        $iso = $DB->Query("SELECT ISO2 FROM {$GLOBALS['prefix']}country WHERE CountryName='".$country."'");
        if($flag = $DB->FetchArray($iso))
        {
            $temp = strtolower($flag[0]);
            if(is_file('Images/Country_Flags/'.$temp.'.png'))
            {
                $flagurl = 'Images/Country_Flags/'.$temp.'.png';
            }else{
                $flagurl = 'Images/Country_Flags/noflag.png';
            }
        }else{
            $flagurl = 'Images/Country_Flags/noflag.png';
        }
        return $flagurl;
    }
    public function getip()
    {
        if (isset($_SERVER))
        {
            if(isset($_SERVER["HTTP_X_FORWARDED_FOR"]))
            {
                $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];

            }else if(isset($_SERVER["HTTP_CLIENT_IP"]))
            {
                $ip = $_SERVER["HTTP_CLIENT_IP"];

            }else{
                $ip = $_SERVER["REMOTE_ADDR"];
            }

        }else{
            if(getenv('HTTP_X_FORWARDED_FOR'))
            {
                $ip = getenv('HTTP_X_FORWARDED_FOR');

            }else if(getenv('HTTP_CLIENT_IP'))
            {
                $ip = getenv('HTTP_CLIENT_IP');

            }else {
                $ip = getenv('REMOTE_ADDR');
            }
        }
        return $ip; 
    }

u can modify this code to get it

Attachments: Images.rar SQL.rar

Write your reply now; next you create a free account (or sign in) and it is posted right away. 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