How to block non-mobile visitors?

ertankoraltan

Newbie
Joined
Dec 18, 2020
Messages
3
Reaction score
0
I need to block all of my non-mobile traffic from one spresific country. Can i do this with cloudflare?
 
You can block country-specific traffic from Cloudflare, dunno about the useragent block though..
 
Why just not including some kind of source to exclude your traffic for a specific country / device?

Code to check if a user is using mobile agent: (Cant paste it here, getting a Console error because of Pregmatch I think)
https://paste.ofcode.org/rVkCAEgDJFFQJhSvcnfRBH


And you can easily get a check where your visitor is from with the following:
PHP:
// Save visitor statistics
if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
      {
        $ip = $_SERVER['HTTP_CLIENT_IP'];
      }
      elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
      {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
      }
      else
      {
        $ip = $_SERVER['REMOTE_ADDR'];
      }
$xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=". $ip);

// Country CODE
$sCountryCode = $xml->geoplugin_countryCode;

And after that you can easily check if $sCountryCode is equal to your country that you want to allow/deny
 
Actually i need something more spesific; i want to block direct traffic and allow only visitors from search engines. Some of my competitors doing this but idk how to do.
 
Actually i need something more spesific; i want to block direct traffic and allow only visitors from search engines. Some of my competitors doing this but idk how to do.

You literally mean cloacking by this. You can check if the user agent is a bot or not, where the IP is from, checking if its a VPN/Datacenter/VPS/Proxy IP.

But you can also check the refer for it.

PHP:
$referer = $_SERVER['HTTP_REFERER'];
if($referer == "")
{
    // Redirect user away
}
 
Back
Top