<?php
// Start Up The Session
session_start();
// Check to see if the keyword session is set
if (empty($_SESSION['keyword'])) {
// Session is not yet set so first determine where the click came from (Google, Yahoo, MSN)
$refer = $_SERVER['HTTP_REFERER'];
if(preg_match("/http:\/\/www.google/", "$refer")) {
// The Click Came From Google So Grab The Keyword
$subject = "$refer";
$pattern = '/q=(.*?)&/';
preg_match_all($pattern,$subject,$match,PREG_SET_ORDER);
// A Match Had To Of Been Made So Strip Out And Reformat The Keyword.
$subject = $match[0][0];
$replacement = array("q=" => "", "&" => "", "+" => " ", "%20" => "");
$keyword = strtr("$subject", $replacement);
trim($keyword);
// Set The Keyword In A Session Var So We Can Use It Only If The User Clicks An Offer
$_SESSION['keyword'] = $keyword;
}
if(preg_match("/http:\/\/search.sympatico.msn/", "$refer")) {
// The Click Came From MSN So Grab The Keyword
$subject = "$refer";
$pattern = '/q=(.*?)&/';
preg_match_all($pattern,$subject,$match,PREG_SET_ORDER);
// A Match Had To Of Been Made So Strip Out And Reformat The Keyword.
$subject = $match[0][0];
$replacement = array("q=" => "", "&" => "", "+" => " ", "%20" => "");
$keyword = strtr("$subject", $replacement);
trim($keyword);
// Set The Keyword In A Session Var So We Can Use It Only If The User Clicks An Offer
$_SESSION['keyword'] = $keyword;
}
if(preg_match("/http:\/\/search.yahoo/", "$refer")) {
// The Click Came From Yahoo So Grab The Keyword
$subject = "$refer";
$pattern = '/p=(.*?)&/';
preg_match_all($pattern,$subject,$match,PREG_SET_ORDER);
// A Match Had To Of Been Made So Strip Out And Reformat The Keyword.
$subject = $match[0][0];
$replacement = array("p=" => "", "&" => "", "+" => " ", "%20" => "");
$keyword = strtr("$subject", $replacement);
trim($keyword);
// Set The Keyword In A Session Var So We Can Use It Only If The User Clicks An Offer
$_SESSION['keyword'] = $keyword;
}
}
?>