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

Why did I have to put it on one line? Anyway shouldn’t I store the result in some session level variable?

Read more here:: How best to check if a user is from China and hide content?

Leave a Reply

Your email address will not be published. Required fields are marked *