php crawler detection -


I'm trying to write sitemap.php which works differently, depending on what's being viewed.

I crawler my sitemap I want to redirect to XML because it should be the most updated page and should contain all the necessary information, but I want my regular readers to show an html sitemap on the php page.

All this will be controlled from within the php header, and I have found on the web which should look like this, but it is not. Can someone crack this for me?

  function getIsCrawler ($ userAgent) {$ crawlers = 'firefox | Google | Msnbot | Rambler | Yahoo | Abacobot | Abhaya | ' | . 'AcioRobot | ASPSeek | CocoCrawler | Dumbot | Fast-web crawler | ' . 'GeonaBot | Gigabot | Lycos | MSRBOT | Scooter | AltaVista | IDBot | EStyle | Condition '; $ Ike crawler = (preg_match ("/ $ crawlers / eye", $ user agent) & gt; 0); The return is $ crawler; } $ Iskrailer = IIS crawler ($ _ server ['HTTP_USER_AGENT']); If ($ isCrawler) {Header ('location: http://www.website.com/sitemap.xml'); Go out; } Else {Echo "No Crawler!"; }  

It looks pretty easy, but as you can see that I've added Firefox to the Agent List, and not enough to make sure I'm not redirected

Thanks for any help :)

You have a mistake in your code:

  $ crawler = getIsCrawler ($ _ SERVER ['HTTP_USER_AGENT']);  

should be $ isCrawler = getIsCrawler ($ _ SERVER ['HTTP_USER_AGENT']);

If you develop with a notice, then you will catch these errors more easily.

In addition, you might want to exit after Header

Warning : Cloaking may be in trouble with search providers. That tells why why.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -