Jump to content

Call Function


intenseone345

Recommended Posts

Hello, how can i add a function call within this php script to echo the result as either "the bot is" or "no bots found" im not sure on how to code it and make use of this script?

Thanks

 

 

<?php
protected function isBot()
{
/* This function will check whether the visitor is a search engine robot */
 
    $bots = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
    "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
    "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
    "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
    "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
    "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
    "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
    "Butterfly","Twitturls","Me.dium","Twiceler");
 
    foreach($bots as $bot)
    {
            if(strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
                return true;
    }
 
    return false;
}
?>
Edited by intenseone345
Link to comment
Share on other sites

Im thinking maybe like this but it wont return the name of the bot done this way.

Also would anyone know how to test a script like this making your own own browser look like a bot, i tried adding "Mozilla" in the array but it did not work?

 

<?php
protected function isBot()
{
/* This function will check whether the visitor is a search engine robot */
 
    $bots = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
    "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
    "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
    "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
    "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
    "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
    "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
    "Butterfly","Twitturls","Me.dium","Twiceler","MSIE","Microsoft Internet Explorer","Mozilla/4.0");
 
    foreach($bots as $bot)
    {
            if(strpos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
                return true;
    }
 
    return false;
}
if (!isBot()) {
    echo "human";
}
if (is_bot()) {
    echo "bot";
}
?>
Link to comment
Share on other sites

For the record, are you posting your exact code? Because if you are then it isn't executing in the first place because it's not valid syntax. Plus, is_bot() does not (as far as you've posted) exist so that won't work either.

 

But to answer the question, you can make the function return not true if it finds the string, but the string it found. It can still return false if not. Then, when you call the function, you assign the return value to a variable and if it's not empty then it'll have the bot name.

 

And one more thing: MSIE, "Microsoft Internet Explorer", and "Mozilla/4.0" are not bots.

Link to comment
Share on other sites

Ok why is this not valid syntax?

thanks for your help

 

<?php
public function isBot()
{
/* This function will check whether the visitor is a search engine robot */
 
    $bots = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
    "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
    "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
    "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
    "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
    "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
    "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
    "Butterfly","Twitturls","Me.dium","Twiceler","Yahoo","Bling","bingbot","ezooms","Baidu");
 
    foreach($bots as $bot)
    {
            if(strpos, strtolower($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
                return true;
    }
 
    return false;
}
if(isBot()) {
    echo ucfirst($bot) . ' ';
} else {
    echo 'no bots';
}
?>
Link to comment
Share on other sites

Your latest code?

 

Because you can't make a function "public" unless it's inside a class.

Because you can't use strpos as just some name floating out in the middle of nowhere.

Because you can't do multiple conditions in an if like that.

Because strtolower() only has one parameter.

Because strtolower() returns a string, not a boolean.

Because if you lowercase the user agent string then you'll never find any bot names with capital letters.

Because you can't use $bot outside of the function where it was defined.

 

I have some bad news: you have no clue what you're doing. If you want the code to be changed then you should find someone to do it for you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.