Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
improved formatting
Source Link
kero
  • 6.3k
  • 1
  • 23
  • 34

To speed up my website in China I thought of hiding blocked services from Chinese users and wrote this and put it in functions.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. }

$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. 
}

Sorry the code formatted strangely. Anyway shouldn'tShouldn't I store the result in some session level variable?

To speed up my website in China I thought of hiding blocked services from Chinese users and wrote this and put it in functions.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. }

Sorry the code formatted strangely. Anyway shouldn't I store the result in some session level variable?

To speed up my website in China I thought of hiding blocked services from Chinese users and wrote this and put it in functions.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. 
}

Shouldn't I store the result in some session level variable?

Source Link
Muskie
  • 115
  • 1
  • 8

How best to check if a user is from China and hide content?

To speed up my website in China I thought of hiding blocked services from Chinese users and wrote this and put it in functions.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. }

Sorry the code formatted strangely. Anyway shouldn't I store the result in some session level variable?