From 161f1935d72dadb12da1a314a91f5da75826b391 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 20 Jul 2013 20:27:35 +0200 Subject: User_agent library: robuster detection in is_referral() --- system/libraries/User_agent.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 2f6f81909..e27004e9e 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -476,8 +476,10 @@ class CI_User_agent { return FALSE; } - $referer = parse_url($_SERVER['HTTP_REFERER']); - return ! (empty($referer['host']) && strpos(config_item('base_url'), $referer['host']) !== FALSE); + $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); + $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); + + return ($referer_host && $referer_host !== $own_host); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From c05ab73237a536802e224b6e8d3a90157eb1b51a Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 20 Jul 2013 20:27:57 +0200 Subject: Cache result of is_referral() --- system/libraries/User_agent.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index e27004e9e..50ac9be98 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -471,15 +471,24 @@ class CI_User_agent { */ public function is_referral() { - if (empty($_SERVER['HTTP_REFERER'])) + static $result; + + if ( ! isset($result)) { - return FALSE; - } + if (empty($_SERVER['HTTP_REFERER'])) + { + $result = FALSE; + } + else + { + $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); + $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); - $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); - $own_host = parse_url(config_item('base_url'), PHP_URL_HOST); + $result = ($referer_host && $referer_host !== $own_host); + } + } - return ($referer_host && $referer_host !== $own_host); + return $result; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b