Last active
March 18, 2020 15:30
-
-
Save hhrealestatemedia/8c36c15bf9fb79aa4147b59117765ccc to your computer and use it in GitHub Desktop.
This file contains 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 | |
function get_keyword($referer) | |
{ | |
$search_phrase = ''; | |
$engines = array('dmoz' => 'q=', | |
'aol' => 'q=', | |
'ask' => 'q=', | |
'google' => 'q=', | |
'bing' => 'q=', | |
'hotbot' => 'q=', | |
'teoma' => 'q=', | |
'yahoo' => 'p=', | |
'altavista'=> 'p=', | |
'lycos' => 'query=', | |
'kanoodle' => 'query=' | |
); | |
foreach($engines as $engine => $query_param) { | |
// Check if the referer is a search engine from our list. | |
// Also check if the query parameter is valid. | |
if (strpos($referer, $engine.".") !== false && | |
strpos($referer, $query_param) !== false) { | |
// Grab the keyword from the referer url | |
$referer .= "&"; | |
$pattern = "/[?&]{$query_param}(.*?)&/si"; | |
preg_match($pattern, $referer, $matches); | |
$search_phrase = urldecode($matches[1]); | |
return array($engine, $search_phrase); | |
} | |
} | |
return; | |
} | |
function get_referrer($my_site) { | |
/* If the referrer is from outside the domain, store the url in a session */ | |
if(!substr($_SERVER['HTTP_REFERER'], 0, strlen($my_site)) !== $my_site) { | |
return $_SERVER['HTTP_REFERER']; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment