Blocking certain queries from google?

Discussion in 'Programming' started by yenerich, Mar 26, 2013.

  1. #1
    Im receiving some spam queries from google and i want to show and 404 header to that specific list or words if they are in the google query.

    I dont know if its better to use php or httaccess.

    Any help are welcome.

    Thanks in advance.
     
    yenerich, Mar 26, 2013 IP
  2. trecords

    trecords Well-Known Member

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #2
    I think php may help here.

    I have just wrote draft code for you, let me know if you get any issue on it:

    <?php
    $bad_words = array("bad","verybad","worst");
     
    foreach ($bad_words as $word) {
        if (preg_match("/$word/", $_SERVER['QUERY_STRING'])) {
            header("Locatin 404.php");
            exit;
        }
    }
     
    ?>
    PHP:
     
    trecords, Mar 26, 2013 IP
  3. yenerich

    yenerich Active Member

    Messages:
    697
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    75
    #3
    I does not work :(
     
    yenerich, Mar 26, 2013 IP
  4. trecords

    trecords Well-Known Member

    Messages:
    145
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #4
    this is ready code, change words inside quotes:
    "bad","verybad","worst"

    and put whole code into header of your index.php file
     
    trecords, Mar 26, 2013 IP
  5. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #5
    What trecords posted is almost correct, updated:

    <?php
    $bad_words = array("bad","verybad","worst");
     
    foreach ($bad_words as $word) {
        if (preg_match("/$word/", $_SERVER['HTTP_REFERER'])) {
            header("Locatin 404.php");
            exit;
        }
    }
     
    ?>
    PHP:
    You can also improve on it to check of the domain is indeed from google.com first.
     
    ThePHPMaster, Mar 31, 2013 IP