How can one detect the search engine bots using php?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I use the following code which seems to be working fine:
update 16-06-2017 https://support.google.com/webmasters/answer/1061943?hl=en
added mediapartners
Check the
$_SERVER['HTTP_USER_AGENT']
for some of the strings listed here:http://www.useragentstring.com/pages/All/
Or more specifically for crawlers:
http://www.useragentstring.com/pages/Crawlerlist/
If you want to -say- log the number of visits of most common search engine crawlers, you could use
You can checkout if it's a search engine with this function :
Then you can use it like :
Here's a Search Engine Directory of Spider names
Then you use
$_SERVER['HTTP_USER_AGENT'];
to check if the agent is said spider.I'm using this code, pretty good. You will very easy to know user-agents visitted your site. This code is opening a file and write the user_agent down the file. You can check each day this file by go to
yourdomain.com/useragent.txt
and know about new user_agents and put them in your condition of if clause.This is the content of useragent.txt
I use this function ... part of the regex comes from prestashop but I added some more bot to it.
Anyway take care that some bots uses browser like user agent to fake their identity
( I got many russian ip that has this behaviour on my site )
One distinctive feature of most of the bot is that they don't carry any cookie and so no session is attached to them.
( I am not sure how but this is for sure the best way to track them )