![](/img/trans.png)
[英]How to validate a “date of birth” using 3 select menu's (PHP & Kohana)?
[英]How to Auto select User's country in registration form's select menu using PHP?
当他从自己的位置使用我的应用程序时,如何在选择框中默认选择用户所在的国家/地区?
在JavaScript或PHP?
请帮我。
提前致谢。
1)下载此数据库并提取csv文件https://sourceforge.net/projects/bowlfish/files/Others/ip2country/ip-to-country.csv.zip/download
在具有5列“ ip_from”(bigint 20),“ ip_to”(bigint 20),country_code2(字符3),country_code3(字符3),country_name(变量50)和import的5列的“ DBname”数据库上创建mysql表“ country_codes” csv文件。
2)使用创建文件country.php
$ip = $_SERVER['REMOTE_ADDR'];
// Establishing a database connection
$dbh=mysql_connect("localhost","DBuser","DBpsw");
mysql_select_db("DBname");
// Query for getting visitor countrycode
$country_query = "SELECT country_code2,country_name FROM country_codes ".
"WHERE ip_from <= inet_aton('$ip') ".
"AND ip_to >= inet_aton('$ip') ";
// Executing above query
$country_exec = mysql_query($country_query);
// Fetching the record set into an array
$ccode_array=mysql_fetch_array($country_exec);
// getting the country code from the array
$country_code=$ccode_array['country_code2'];
// getting the country name from the array
$country_name=$ccode_array['country_name'];
// Display the Visitor coountry information
// echo "$country_code - $country_name";
// Closing the database connection
mysql_close($dbh);
?>
3)include_once'country.php'; 在表单文件中并使用$ country_name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.