|
-
Apr 19th, 2004, 08:27 PM
#1
Thread Starter
Ex-Super Mod'rater
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.

-
Apr 20th, 2004, 02:46 PM
#2
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.
-
Apr 20th, 2004, 02:54 PM
#3
<?="Moderator"?>
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.
-
Apr 20th, 2004, 02:57 PM
#4
Thread Starter
Ex-Super Mod'rater
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.

-
Apr 20th, 2004, 03:04 PM
#5
Thread Starter
Ex-Super Mod'rater
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.

-
Apr 21st, 2004, 01:51 AM
#6
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.
-
Apr 21st, 2004, 11:48 AM
#7
Thread Starter
Ex-Super Mod'rater
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|