我如何能附加国家识别脚本到我的注册页面,并使其陈述


how i can attach country identification script to my signup page and make if statments?

我做了三个国家的组框我们,英国,他们的状态,所以问题我不知道如何使页面显示适当的组框的签名者(我的意思是,当一个签名者是从加拿大它必须出现给他的加拿大省份的列表相同的美国一个和英国一个),所以显然我不知道如何将脚本附加到我的注册页面Ps:我不太擅长PHP,所以如果可能的话,如果你能详细解释一下,那就太好了

    <?php
    $IPaddress=$_SERVER['REMOTE_ADDR']; 
    $two_letter_country_code=iptocountry("$IPaddress");
    function iptocountry($ip) {   
    $numbers = preg_split( "/'./", $ip);   
    include("ip_files/0.php");
include("ip_files/1.php");
include("ip_files/2.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){$country=$ranges[$key][1];break;}
        }
    }
    if ($country==""){$country="unkown";}
    return $country;
     }
     ?>

我建议你使用hostinfo API。http://www.hostip.info/use.html。

http_GET('http://api.hostip.info/country.php?ip=12.215.42.19'.$ip);

返回国家id(例如:"US"代表美国)

把它放在<select>元素的<?php ?>中。然后,一旦确定了国家,就使用一个州数组,并在其中循环,将选项元素添加到select节点:

switch ($country) {
case "US":
$states = array("state1", "state2" );
    break;
case "UK":
....
}
foreach($states as $state) 
{
   $state = htmlspecialchars($state);
   echo '<option value="'. $state .'">'. $state .'</option>';
}

这里有一个例子-你需要把国家代码生成器在你自己的代码虽然(我没有必要的i_files):http://pastebin.com/pTpEStHj

工作示例(示例国家代码):http://fotest.co.nf/index%20-%20Copy.html