Page 1 of 1

stats spiders 2

Posted: Tue Apr 11, 2006 7:04 am
by dal_oscar
Weirdan | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi,

I am using 'crawler' in get_browser  to check if a visitor is a spider/crawler

Code: Select all

$isspider=0;
$ua = get_browser(); 
if ($ua['crawler'] == TRUE) 
 $isspider=1;
And then in my code, I check the value of $isspider to dump the data accordingly. The problem is, that $ua[crawler] always seems to be null. I am also storing the HTTP_USER_AGENT values, and saw using those that an MSNbot just visited my website. But $ua['crawler'] fails to register this (it is always null).

Any ideas?

Thanks.

P.S.- I also posted a related query last friday viewtopic.php?t=46766, and have got to this stage now, but am still running into trouble


Weirdan | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Apr 11, 2006 7:22 am
by feyd
The default behaviour for get_browser() is to return an object, not an array.

Posted: Tue Apr 11, 2006 8:41 am
by dal_oscar
I changed that to $ua->crawler (if thats what you meant), and it now doesnt return null but 0 everytime now (whether or not it is a crawler) please help.

Posted: Tue Apr 11, 2006 10:04 am
by John Cartwright
change the second argument to true to change the return to an array.

Posted: Wed Apr 12, 2006 4:03 am
by dal_oscar
Changed that......now it looks like

Code: Select all

$isspider=0;
$ua = get_browser(null,TRUE); 
if ($ua->crawler == TRUE) 
       $isspider=1;
It still registers $ua->crawler as null, - whether it is a crawler or not.

Posted: Wed Apr 12, 2006 8:53 am
by feyd
with the second argument being true, the returned information is an array. var_dump($ua).

Posted: Wed Apr 12, 2006 8:57 am
by R4000

Code: Select all

function iscrawler($ua = null){
 $userag = get_browser($ua,TRUE);
 if ($userag['crawler'] == TRUE) return true;
 return false;
}
use like:

Code: Select all

if(iscrawler()){
 echo "CRAWLER!";
} else {
 echo "NOT CRAWLER!";
}

Posted: Wed Apr 12, 2006 9:10 am
by dal_oscar
OK...a big thanks to everyone trying to help me. Though I am no where near a solution, and have no idea what to do - thanks a lot for your patience while dealing with my newbie queries!!!

R4000, your function doesnt seem to help. It says not crawler all the time.

Feyd, double thanks for bearing with me sicne yesterday (or rather last friday), but now you've totally lost me...var_dump(), is returning bool(false). What is this telling me?

I am totally lost - would appreciate someone telline me what I am doing wrong

Posted: Wed Apr 12, 2006 9:12 am
by R4000
well are you testing that function with your browser??

cause it will only work if its a crawler viewing the site

Posted: Wed Apr 12, 2006 9:14 am
by dal_oscar
No, I am simulating a crawler, by using this
http://www.hashemian.com/tools/browser-simulator.htm

Posted: Wed Apr 12, 2006 9:16 am
by dal_oscar
Apologies Feyd (Thread locked. This is the exact same "problem" in your last thread. Continue to use it.)

I had created the other thread accidently.