Results 1 to 7 of 7

Thread: Checing for a SubString -[RESOLVED]-

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    Checing for a SubString -[RESOLVED]-

    I am using this code in my counter to stop it counting known robots as unique hits
    PHP Code:
    if (strpos($_SERVER['HTTP_USER_AGENT'],'SurveyBot'))
    {
      
    $IsRobot true;

    This is used with more elseif's in order to go though all the robots I know of so far. However I still seem to be getting my Counter creating records in my Db that say the User Agent is "SurveyBot/2.3 (Whois Source)" even witht he code above. Have I made a mistake in the code above you do you recon the problem may be with another part in my code?

    Thanx for any help.
    Last edited by Electroman; Apr 21st, 2004 at 11:48 AM.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    Try this out:
    PHP Code:
    if(strstr($_SERVER['HTTP_USER_AGENT'], 'SurveyBot')){
      
    $IsRobot true;
    }elseif(.... 
    I've always used strstr(), strpos() didn't work for me the first time I wanted to see if a string occured within another, so it's just stuck in my head for what I use. It's said to be slower and use more memory, but see if that helps.

    Or, you could try:
    PHP Code:
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'SurveyBot') === true){
      
    $IsRobot true;
    }elseif(.... 
    Last edited by kows; Apr 20th, 2004 at 02:50 PM.
    Like Archer? Check out some Sterling Archer quotes.

  3. #3
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099
    If you want to use strpos try this

    PHP Code:
    if (strpos($_SERVER['HTTP_USER_AGENT'],'SurveyBot') == false)
    {
      
    $IsRobot true;

    Kows: It returns an integer if it finds the string. So if the string is at the start it will return 0, which is also evaluated to false in an IF statement.

  4. #4

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Thanx, Mind the strings i'm using might be part way though as well, not all of them are at the beginning though.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  5. #5

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Opps, I thought I had made this change in the first example:
    PHP Code:
    if (strpos(" ".$_SERVER['HTTP_USER_AGENT'],'SurveyBot')) 

      
    $IsRobot true

    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Actually to check for failure of strpos, use
    strpos(...) === false
    (notice the triple equals), because otherwise 0 gets interpreted as false.

    Alternatively I think there's an in_string or instr function.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    Thanx guys, I have just had google bot return to my site and confirm it now works with:
    PHP Code:
    if (strpos(' '.$_SERVER['HTTP_USER_AGENT'],'Mediapartners-Google') != 0)
    {
      
    $UserID 270;

    So I guess I'll keep it like this until I get some time to look at the in_string function CornedBee mentioned.
    When your thread has been resolved please edit the original post in the thread ()
    and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.

    When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

Posting Permissions

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



Click Here to Expand Forum to Full Width