Bot Cover Shield

Posted August 23rd, 2009 in Blog by admin

Today, I finished Bot Cover Shield with PHP. My blog ,www.saturngod.net, always occur CPU limit over and I think many bot come to my blog. So, I stop the bot and I just allow google bot. In Theory, Bot can’t save cookies (it may be use cookies but not sure). So, I am using saving cookies system.

[sourcecode lang="php"]
<?php
if(isset($_POST['submit_dos']))
{
    setcookie(“checkhuman”, “process”, time()+3600);
    header(“Location:”.$_SERVER['HTTP_REFERER' ]);
}
function chkcookies()
{
    if(isset($_COOKIE["checkhuman"]))
    {
        if($_COOKIE["checkhuman"]==”process”)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
if(! chkcookies())
{

    $ip=$_SERVER['REMOTE_ADDR'];

    if(($ip != “66.249.66.1″) && ($ip != “66.249.65.133″) && ($ip != “66.249.67.72″) && ($ip != “66.249.72.137″))
    {
        echo “If you are human click “;
        echo “<form action=’index.php’ method=post>”;
        echo “<input type=’submit’ value=’here’ name=’submit_dos’ /></form>”;
        exit();
    }

}
?>
[/sourcecode]

I add this code in header.php of wordpress template. So, our blog can cover the bots easily.