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("".$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?

Muskie 1 month 0 Answers 7 views 0

Leave an answer