0

以下のスクリプトは、すべてのボット アクセスのログ ファイルを作成し、私に電子メールを送信し、ip2location で IP を検証します。PHP5.2 の eregi 関数で問題なく動作したので、eregi 行を preg_match に変更し、「reg_match():区切り文字は英数字またはバックスラッシュであってはなりません」という警告が表示されましたが、現在は機能せず、visits.log ファイルにボットが記録されません。

スクリプトは引き続き以下の 3 つの警告を表示しますが、これらは警告であり、機能し始めていたため、あまり注意を払いませんでした。

  • 注意: 未定義のオフセット: C:\wamp\www\visits.php の 28 行目の 5
  • 警告: preg_match(): C:\wamp\www\visits.php の 28 行目に空の正規表現があります
  • 注意: 未定義のインデックス: 62 行目の C:\wamp\www\visits.php の js
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

  $to = "email@here.com";

  $log = "./visits.log";

  $dateTime = date("r");


  $agents[] = "/googlebot/";
  $spiders[] = "/Google/";
  $spiders[] = "/Googlebot/";
  $agents[] = "/slurp/";
  $spiders[] = "/Slurp (Inktomi's robot, HotBot)/";
  $agents[] = "/msnbot/";
  $spiders[] = "/MSN Robot (MSN Search, search\.msn\.com)/";
  $agents[] = "/yahoo\! slurp/";
  $spiders[] = "/Yahoo! Slurp/";
  $agents[] = "/bingbot/";
  $spiders[] = "/Bing\.com/";
  $ip= $_SERVER['REMOTE_ADDR'];
  $found = false;

  for ($spi = 0; $spi < count($spiders); $spi++)
    if ($found = preg_match($agents[$spi], $_SERVER['HTTP_USER_AGENT']))
      break;

  if ($found) {
    $url = "http://" . $_SERVER['SERVER_NAME']. $_SERVER['PHP_SELF'];

    if ($_SERVER['QUERY_STRING'] != "") {
      $url .= '?' . $_SERVER['QUERY_STRING'];
    }

    $line = $dateTime . " " . $spiders[$spi] . " " . $ip." @ " . $url;
    $ip2location = "https://www.ip2location.com/".$_SERVER['REMOTE_ADDR'];

    if ($log != "") {
      if (@file_exists($log)) {
        $mode = "a";
      } else {
        $mode = "w";
      }

      if ($f = @fopen($log, $mode)) {
        @fwrite($f, $line . "\n");
        @fclose($f);
      }
    }

   if ($to != "") {
$to = "email@here.com";
$subject = $spiders[$spi]. " crawled your site";
$body = "$line". "\xA\xA" ."Whois verification available at: $ip2location";
mail($to, $subject, $body);
    }
  }

  if ($_REQUEST["js"]) {
     header("Content-Type: image/gif\r\n");
     header("Cache-Control: no-cache, must-revalidate\r\n");
     header("Pragma: no-cache\r\n");

     @readfile("visits.gif");
  }

?>
4

2 に答える 2