stats spiders 2

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dal_oscar
Forum Newbie
Posts: 21
Joined: Fri Apr 07, 2006 6:00 am
Location: UK

stats spiders 2

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The default behaviour for get_browser() is to return an object, not an array.
dal_oscar
Forum Newbie
Posts: 21
Joined: Fri Apr 07, 2006 6:00 am
Location: UK

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

change the second argument to true to change the return to an array.
dal_oscar
Forum Newbie
Posts: 21
Joined: Fri Apr 07, 2006 6:00 am
Location: UK

Post 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.
Last edited by dal_oscar on Thu Apr 13, 2006 4:37 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

with the second argument being true, the returned information is an array. var_dump($ua).
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post 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!";
}
dal_oscar
Forum Newbie
Posts: 21
Joined: Fri Apr 07, 2006 6:00 am
Location: UK

Post 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
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

well are you testing that function with your browser??

cause it will only work if its a crawler viewing the site
dal_oscar
Forum Newbie
Posts: 21
Joined: Fri Apr 07, 2006 6:00 am
Location: UK

Post by dal_oscar »

No, I am simulating a crawler, by using this
http://www.hashemian.com/tools/browser-simulator.htm
dal_oscar
Forum Newbie
Posts: 21
Joined: Fri Apr 07, 2006 6:00 am
Location: UK

Post 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.
Post Reply