Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4069190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:28:12+00:00 2026-05-20T16:28:12+00:00

hi I just want your opinions about this code I found on a website

  • 0

hi I just want your opinions about this code I found on a website for detect real search spiders from spammer is it good?? and do you have any recommendations for other scripts or methods for this subject

<?php 
$ua = $_SERVER['HTTP_USER_AGENT'];

$spiders=array('msnbot','googlebot','yahoo');

$pattern=array("/\.google\.com$/","/search\.live\.com$/","/\.yahoo\.com$/");

for($i=0;$i < count($spiders) and $i < count($pattern);$i++)

{

  if(stristr($ua, $spiders[$i])){

    //it's pretending to be MSN's bot or Google's bot

    $ip = $_SERVER['REMOTE_ADDR'];

    $hostname = gethostbyaddr($ip);



    if(!preg_match($pattern[$i], $hostname))

    {

      //the hostname does not belong to either live.com or googlebot.com.

      //Remember the UA already said it is either MSNBot or Googlebot.

      //So it's a spammer.

      echo "spammer";

      exit;

    }

    else{

      //Now we have a hit that half-passes the check. One last go:

      $real_ip = gethostbyname($hostname);

      if($ip != $real_ip){

        //spammer!

        echo "Please leave Now spammr";

        break;

      }

      else{

        //real bot

      }

    }

  }

  else

  {

    echo "hello user";

  }

}

note: it used user agent switcher with this code and it worked perfectly but am not sure if it will work in real world, so what do you think??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:28:12+00:00Added an answer on May 20, 2026 at 4:28 pm

    What would keep a spammer from simply giving an entirely correct user agent string?

    I think this is fairly pointless. You would have to at least compare IP ranges (or their name servers) as well in order to get reliable results. This is possible for Google:

    Google Webmaster Central: How to verify Googlebot

    but even if you test for Google and Bing this way, a spambot can enter your site simply by giving a browser user-agent. Therefore, it is ultimately impossible to detect a spam-bot. They are a reality, and there is no good way to keep them out from a web site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to ask for your experience. I'm designing a public website, using
I just want to know what is your opinion about how to fingerprint/verify html/links
Just want to know how to read an attribute of a parent node from
I just want to clarify one thing. This is not a question on which
i just have a little design question. If i got this code public Interface
Preface: This is not much about how to structure code within files. I have
I want to ask your opinion about one specific aspect of endless Qt vs
So basically I have got an idea and I want to hear your opinions
I'm planning to build small plugin in jQuery - just want to check your
I'm creating my own blog in PHP and want to know your opinions on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.