O
O
oxxoll2021-12-14 19:26:48
PHP
oxxoll, 2021-12-14 19:26:48

How to add search bots to the redirect exception?

How to add a redirect exception so that the bots stay on the site? I will thank the donate for the working solution)

//Получаем IP пользователя
$ip =  $_SERVER['REMOTE_ADDR'];

//Функция whois для определения страны по IP\
function whois($ip) {
  if ($ip!="") {
    $sock = fsockopen ("whois.ripe.net",43,$errno,$errstr);
    if ($sock) {
       fputs ($sock, $ip."\r\n");
      while (!feof($sock)) {
        $str.=trim(fgets ($sock,128)." <br>");
      }
    }
    else {
          $str.="$errno($errstr)";
      return;
    }
    fclose ($sock);
  }
  return $str;
  }

//Получаем whois данные для IP пользователя
$whois =  whois($_SERVER['REMOTE_ADDR']);

//Получаем страну, исходя из whois IP
$need = "country:";
 $pos = strpos($whois,$need);
 $search = substr($whois,$pos,18);
 $excount = explode(":", $search);
 $country = trim($excount[1]);

//Ну и сам код редиректа
if($country == "RU") {
header('Location: /ru/);
exit();
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question