为了加快我在中国的网站速度,我想对中国用户隐藏被屏蔽的服务,于是写了这篇文章并将其放入函数中。php
$isInChina = false;
$ip = $_SERVER[\'REMOTE_ADDR\']; // This will contain the ip of the request
// This service tells me where the IP address is from and gives me more data than I need.
$userData = json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
if (is_Null($userData) || empty($userData) || $userData->geoplugin_countryCode == "CN")
{
$isInChina = true; // Count no data as in China maybe to be paranoid.
}
我不应该将结果存储在某个会话级别变量中吗?