From b8a38c2fb60f37a507c2e5631bc56372a36ff818 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 30 Sep 2015 18:46:22 +0200 Subject: [PATCH] Add a isHuman() method to the Browser class with some basic checks on bot or human request --- system/src/Grav/Common/Browser.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/system/src/Grav/Common/Browser.php b/system/src/Grav/Common/Browser.php index 051f2c1ef..3577d0409 100644 --- a/system/src/Grav/Common/Browser.php +++ b/system/src/Grav/Common/Browser.php @@ -38,4 +38,20 @@ class Browser $version = explode('.', $this->getLongVersion()); return intval($version[0]); } + + /** + * Determine if the request comes from a human, or from a bot/crawler + */ + public function isHuman() + { + if (empty($this->getBrowser())) { + return false; + } + + if (preg_match('~(bot|crawl)~i', $this->getBrowser())) { + return false; + } + + return true; + } }