Jump to content


Recognizing Google


4 replies to this topic

#1 Lang

    Young Padawan

  • Members
  • Pip
  • 198 posts
  • Gender:Male
  • Location:Ontario, Canada

Posted 14 November 2006 - 07:09 PM

As Google crawls my site it clicks links it reports posts on my forum. I have a function so it detects if the user reporting the post is in fact Google. The function is below - the only problem is it doesn't seem to be working. If anyone sees why, it'd be greatly appreciated.

function Error($error, $what, $time, $page, $find){
	$ip = $_SERVER['REMOTE_ADDR'];

	$from = $_SERVER['HTTP_USER_AGENT'];	
	$find = 'Google';
	$pos = strpos($from, $find);

	if ($pos === true){
		//DO NOTHING
	}else{
			   //LOG ERROR
	}
}

I use USER AGENT because Google is usually if not always in the name.

Thanks,

#2 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 15 November 2006 - 11:19 AM

I would always use a preg_match, find them better:

$pos = preg_match("/Google/", $_SERVER['HTTP_USER_AGENT'], $matches);

if(count($matches) > 0) {
	//Do Nothing
} else {
	//Log Error
}


#3 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 15 November 2006 - 12:59 PM

Well, what about all the other search engines crawlers? Yahoo, ask Yeeves etc...

You would probably be better off creating a robots.txt file and block access to that particular file instead.

--

edited by Mr. Matt, please don't double post.

#4 SiteReboot

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Gender:Male
  • Interests:www.sitereboot.com

Posted 19 November 2006 - 10:01 AM

View PostAv-, on Nov 15 2006, 01:59 PM, said:

Well, what about all the other search engines crawlers? Yahoo, ask Yeeves etc...

You would probably be better off creating a robots.txt file and block access to that particular file instead.

--

edited by Mr. Matt, please don't double post.


Yes except search engines do not always follow the robots.txt settings

#5 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 19 November 2006 - 02:53 PM

Anybody with a good reputation will follow what is in robots.txt. In fact, most sites will even tell you, "Put this in your robots.txt file if you want/don't want something to happen." I know google does and i believe i've even seen something on Yahoo about it.

And matt, preg_match() technically doesn't find them any better than the str*() functions. But i would agree with the fact that you shouldn't use strpos() for this, strstr() would be more ideal.

Also, as php.net said...

Quote

Tip: Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users