我如何根据IP地址确定用户的目前地点(我猜测这一方式如何运作)。
I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...
我如何根据IP地址确定用户的目前地点(我猜测这一方式如何运作)。
<?php
$user_ip = getenv( REMOTE_ADDR );
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
$country = $geo["geoplugin_countryName"];
$city = $geo["geoplugin_city"];
?>
Edited
<?php
function get_client_ip()
{
$ipaddress = ;
if (isset($_SERVER[ HTTP_CLIENT_IP ])) {
$ipaddress = $_SERVER[ HTTP_CLIENT_IP ];
} else if (isset($_SERVER[ HTTP_X_FORWARDED_FOR ])) {
$ipaddress = $_SERVER[ HTTP_X_FORWARDED_FOR ];
} else if (isset($_SERVER[ HTTP_X_FORWARDED ])) {
$ipaddress = $_SERVER[ HTTP_X_FORWARDED ];
} else if (isset($_SERVER[ HTTP_FORWARDED_FOR ])) {
$ipaddress = $_SERVER[ HTTP_FORWARDED_FOR ];
} else if (isset($_SERVER[ HTTP_FORWARDED ])) {
$ipaddress = $_SERVER[ HTTP_FORWARDED ];
} else if (isset($_SERVER[ REMOTE_ADDR ])) {
$ipaddress = $_SERVER[ REMOTE_ADDR ];
} else {
$ipaddress = UNKNOWN ;
}
return $ipaddress;
}
$PublicIP = get_client_ip();
$json = file_get_contents("http://ipinfo.io/$PublicIP/geo");
$json = json_decode($json, true);
$country = $json[ country ];
$region = $json[ region ];
$city = $json[ city ];
?>
<?php
$query = @unserialize (file_get_contents( http://ip-api.com/php/ ));
if ($query && $query[ status ] == success ) {
echo Hey user from . $query[ country ] . , . $query[ city ] . ! ;
}
foreach ($query as $data) {
echo $data . "<br>";
}
?>
利用这一来源对这项法典进行查询。 页: 1
Try this Code using the hostip.info 服务:
$country=file_get_contents( http://api.hostip.info/get_html.php?ip= );
echo $country;
// Reformat the data returned (Keep only country and country abbr.)
$only_country=explode (" ", $country);
echo "Country : ".$only_country[1]." ".substr($only_country[2],0,4);
由于PHP依靠服务器,可以提供实时地点。 只能提供固定地点。 最好避免将 Java印成一个地点,而不是使用PHP。
但是,需要将贾瓦文数据张贴到PHP上,以便能够方便地向服务器上的一个方案提供。
IP地址给你一个非常不可靠的地点。 如果把地点放在第一线是关键的话,那么你可以把地点装上Java号。 (此外,用户需要允许查阅。)
旧的 免费电离层光电灯现在被涂上,将于2018-07-01停止。
新的预报系统从ipstack>。 你们必须打造账户。 然后,你可以使用APURL中的存取钥匙。
$url = "http://api.ipstack.com/122.167.180.20?access_key=ACCESS_KEY&format=1";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response = json_decode($response);
$city = $response->city; // You can get all the details like longitude, latitude from the $response .
详情请上<https://github.com/apilayer/freegeoip” rel=“nofollow noreferer”>freegeoip 。 (Git/2007/5)。
I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...
<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...
I found this script online that creates a thumbnail out of a image but the thumbnail image is created with poor quality how can I improve the quality of the image. And is there a better way to create ...
如何确认来自正确来源的数字。
Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...
I wonder there is a way to post a message to a facebook business page with cURL? thanks
I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...
How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...