// SEARCH ENGINE CHECKER FUNCTION /* $ref is optional, if not set will use current! */ function seReferer($ref = false){ $SeReferer = (is_string($ref) ? $ref : $_SERVER['HTTP_REFERER']); if( //Check against Google, Yahoo, MSN, Ask and others preg_match( "/[&\?](q|p|w|searchfor|as_q|as_epq|s|query)=([^&]+)/i", $SeReferer,$pcs) ){ if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){ $SeDomain = trim(strtolower($SeDomain[1])); $SeQuery = $pcs[2]; if(preg_match("/[&\?](start|b|first|stq)=([0-9]*)/i",$SeReferer,$pcs)){ $SePos = (int)trim($pcs[2]); } } } if(!isset($SeQuery)){ if( //Check against DogPile preg_match( "/\/search\/web\/([^\/]+)\//i", $SeReferer,$pcs) ){ if(preg_match("/https?:\/\/([^\/]+)\//i",$SeReferer,$SeDomain)){ $SeDomain = trim(strtolower($SeDomain[1])); $SeQuery = $pcs[1]; } } } // We Do Not have a query if(!isset($SeQuery)){ return false; } $OldQ=$SeQuery; $SeQuery=urldecode($SeQuery); // The Multiple URLDecode Trick to fix DogPile %XXXX Encodes while($SeQuery != $OldQ){ $OldQ=$SeQuery; $SeQuery=urldecode($SeQuery); } //-- We have a query return array( "Se"=>$SeDomain, "Query"=>$SeQuery, "Pos"=>(int)$SePos, "Referer"=>$SeReferer ); } //set cookie name and expiration $cookie_name = 'reftype'; $expire = time()+60*60*24*30; if (!array_key_exists($cookie_name, $_COOKIE)) { // If no cookie exists for the referrer type then check it and set it //call the function to check for search engine referrer $se = seReferer(); if (is_array($se)) { // array was created by function, so SEARCH ENGINE was found $cookie_ref_type = 'Engine'; } else { // no array, so no engine $cookie_ref_type = 'NoEngine'; } setCookie($cookie_name, $cookie_ref_type, '0', '/'); // 0 expiration specific so it deletes on session end // now set the cookie based on what we found } // ---------------------------------------------------------------------------- ?>