Created
April 11, 2012 17:53
-
-
Save rissajeanne/2360908 to your computer and use it in GitHub Desktop.
httpRefererMatchesBaseUrl()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function httpRefererMatchesBaseUrl() { | |
if (!array_key_exists('HTTP_REFERER', $_SERVER) || | |
!get_instance()->config->item('base_url')) { | |
return false; | |
} | |
$baseUrl = parse_url(get_instance()->config->item('base_url')); | |
$referer = parse_url($_SERVER['HTTP_REFERER']); | |
$cleanHttpReferer = $referer['host']; | |
$cleanBaseUrl = $baseUrl['host']; | |
// Strip the "m." prefix, if it exists | |
if (stripos($cleanBaseUrl, 'm.') === 0) { | |
$cleanBaseUrl = substr($cleanBaseUrl, 2); | |
} | |
if (stripos($cleanHttpReferer, 'm.') === 0) { | |
$cleanHttpReferer = substr($cleanHttpReferer, 2); | |
} | |
// Strip the lang subdomain, if it exists | |
if (stripos($cleanBaseUrl, '.') === 2) { | |
$cleanBaseUrl = substr($cleanBaseUrl, 3); | |
} | |
if (stripos($cleanHttpReferer, '.') === 2) { | |
$cleanHttpReferer = substr($cleanHttpReferer, 3); | |
} | |
return ($cleanHttpReferer === $cleanBaseUrl); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment