Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder ArcticFox's Avatar
    Join Date
    Jan 2004
    Location
    Vostok Station, AQ
    Posts
    602
    Thanks
    35
    Thanked 3 Times in 3 Posts

    Internet Explorer Nothing up my sleeves...

    I have this code:
    PHP Code:
    if (strstr($_SERVER["HTTP_USER_AGENT"], "VoilaBot")) {header("location: http://www.parnasse.com/trap.html");} 

    I'd like to be able to do this:
    PHP Code:
    if (strstr($_SERVER["HTTP_USER_AGENT"], "")) {header("location: http://www.parnasse.com/trap.html");} 
    If there's nothing captured in the HTTP_USER_AGENT (ie: "")then it would location:http:/ /www.parnasse.com/trap.html

    But as it is, I get Warning: strstr() [function.strstr]: Empty delimiter.


    Tips, please?
    <div> - putting your mind in a box since 1997

  • #2
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    How about this: add function to a globally required site config file:

    PHP Code:
    function agentCheck() {
       
    $agent = (!empty($_SERVER["HTTP_USER_AGENT"])) ? $_SERVER["HTTP_USER_AGENT"] : 'Not Defined';
       
    $agentOK true;
       
    $blackList = array('bot1',
                          
    'bot2',
                          
    'bot3');

       foreach(
    $blackList as $bot){
           
    $agentOK = ( stristr($agent,$bot ) ? true false;
              if(!
    $agentOK) {
                
    header('Location: http://www.spampoison.com/');
                break;
                exit;
              }
       }
     } 
    Add "$botCheck= agentCheck();" to the top of each page that you want to screen for bots.

    {edit}
    if you want to send empty string agents to spam trap, add 'Not Defined' to the $blackList array.
    {/edit}
    Last edited by meth; 02-28-2007 at 01:19 AM.
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,798
    Thanks
    19
    Thanked 156 Times in 147 Posts
    you should probably be using strpos if you just want to check for the occurrence of one string inside of another...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #4
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    stripos to be more specific. stristr is used for reporting purposes in this function's original context.
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #5
    Regular Coder ArcticFox's Avatar
    Join Date
    Jan 2004
    Location
    Vostok Station, AQ
    Posts
    602
    Thanks
    35
    Thanked 3 Times in 3 Posts

    Internet Explorer

    I don't suppose this would work then:

    PHP Code:
    if (strstr($_SERVER["HTTP_USER_AGENT"],    "Not Defined"))       {header("location: http://www.voila.com/");} 
    <div> - putting your mind in a box since 1997


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •