최근 수정일 : 2010-09-09 21:40:15 - youshine
글 작성한 곳 :
2010.09.09 21:40:14 (*.248.87.183)
다음 링크에 가니 이런 코드가 있군요...
http://www.phptutorial.info/iptocountry/the_script.html#basic
Getting the IP address of
visitors, and displaying country and flag
In case you want to
display flags in your page, download Flags file in the top of this page,
and save all pictures to a folder named "flags" .
We have added a few lines of code to script is previous example
(in red) which
allows showing country specific flags in our pages. This code will
check
whether a gif file containing the two country code exists in "flags"
folder and displays it. In case the gif file in not in the folder, a
default white flag is displayed. In case you have any of the missing
flags, please send
them to us.
$IPaddress=$_SERVER['REMOTE_ADDR'];
$two_letter_country_code=iptocountry($IPaddress);
include("IP_FILES/countries.php");
$three_letter_country_code=$countries[ $two_letter_country_code][0];
$country_name=$countries[$two_letter_country_code][1];
print "Two letters code: $two_letter_country_code<br>";
print "Three letters code: $three_letter_country_code<br>";
print "Country name: $country_name<br>";
// To display flag
$file_to_check="flags/$two_letter_country_code.gif";
if (file_exists($file_to_check)){
print "<img src=$file_to_check width=30 height=15><br>";
}else{
print "<img src=flags/noflag.gif width=30 height=15><br>";
}
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;
}
?>
백성찬(白星燦)
처음 글 작성 언어와 혼돈이 올 수 있기 때문에 사용하는 것입니다.