//STEP: 1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
include("admin/inc/db.php");
$conn = getDBConnection();
//STEP:2
global $cid;
global $ctscookie;
global $cookiepresent;
global $hpg_rga_cookie_values;
global $useragent;
$useragent = $HTTP_USER_AGENT;
$useragent = $_SERVER["HTTP_USER_AGENT"];
$hpg_rga_cookie_values = $HTTP_COOKIE_VARS["hpg"];
if(isset($hpg_rga_cookie_values) && $hpg_rga_cookie_values!="")
{
$_SESSION["hpg"] = $hpg_rga_cookie_values;
}
//Step:3
//$cid = $_GET["cid"];
$exp = explode("/",$_SERVER["REQUEST_URI"]);
$numofparams = count($exp);
$cid = $exp[$numofparams-1];
//echo("
cid : ".$cid);
if(trim($cid) == "")
{
//Dont set cookie just redirect to landing page.
$cookiepresent =1;
openLandingPage();
exit();
}
$cookiename = "ctscreative";
//Step:4
$ctscookie = $HTTP_COOKIE_VARS[$cookiename];
//echo("
ctscookie : ".$ctscookie);
if (isset ($ctscookie) && trim($ctscookie)==trim($cid))
{
//Step:4a
//echo("
cookie is already set and the creativecode is also same: open Landing Page");
$cookiepresent =1;
openLandingPage();
}
else
{
//Step:4b
//echo("
cookie is not set or the creative code is different. set the cookie and load the landing page");
$cookiepresent =0;
setCts($cookiename);
openLandingPage();
}
//------------------------------------------------------------------------------
//Function :setCts
//This function set the Campaign Tracking System Cookie in the client machine
//------------------------------------------------------------------------------
function setCts($cookiename){
global $cid;
$today = getdate();
$month = $today['mon'];
$mday = $today['mday'];
$year = $today['year'];
$createdon = $year."-".$month."-". $mday;
$expires = time()+(3600*24*30); //approximatly 30 days
setcookie($cookiename, $cid,$expires,"/");
}
//------------------------------------------------------------------------------
function openLandingPage()
{
$filename = getLandingPageURL();
//echo "
Landing Page : $filename";
$file = fopen ($filename, "r");
if (!$file) {
echo "
Unable to open remote file.\n";
exit;
}
while (!feof ($file)) {
$line = fgets ($file, 1024);
if(strpos($line,"
")>=0)
{
$line = str_replace("","\n",$line);
}
if(strpos($line,"")>=0)
{
$line = str_replace("","\n",$line);
}
echo($line );
}
fclose($file);
setCookieTracker(); //Set the client side code for triggering the cookie tracer
}
//------------------------------------------------------------------------------
function setCookieTracker()
{
global $cid;
global $cookiepresent;
$host = getHost();
$url = $host."/ctsisset.php?cookiepresent=$cookiepresent&cid=$cid";
?>
}
//------------------------------------------------------------------------------
function getHost()
{
$host = trim($_SERVER['HTTP_HOST']);
if($host != "attackinga.ragedev:81" && $host != "stresscenter.ragedev")
{
$host="http://www.stresscenter.com";
}
else
{
$host="http://".$host;
}
return $host;
}
//------------------------------------------------------------------------------
function getLandingPageURL()
{
global $cid;
global $ctscookie;
global $campaignid;
global $uid;
global $defaulturl;
global $useragent;
global $hpg_rga_cookie_values;
$useragent = urlencode($useragent);
$host = getHost();
//echo "
host : $host";
if($host != "http://attackinga.ragedev:81" || $host != "http://stresscenter.ragedev")
{
$host="http://www.stresscenter.com";
}
else
{
$host=$host;
}
$defaulturl = $host;
$url="";
$strsql = "SELECT * FROM tblctscampaignmediacreatives where creativecode='".$cid."'";
$result=mysql_query($strsql);
$recordcount = mysql_num_rows($result);
if($recordcount >0){
$line = mysql_fetch_array($result);
$url = $line["url"];
$mediaid = $line["mediaid"];
//echo "
creativeurl : ".$url;
if($url=="") // if creative doesnot have url
{
$strsql = "SELECT * FROM tblctscampaignmedias where mediaid='".$mediaid."'";
//echo("
strsql : $strsql");
$result=mysql_query($strsql);
$recordcount = mysql_num_rows($result);
if($recordcount >0){
$line = mysql_fetch_array($result);
$url = $line["mediaurl"];
$campaignid = $line["campaignid"];
//echo "
media url : ".$url;
if($url=="") // if media doesnot have url
{
$strsql = "SELECT * FROM tblctscampaignmaster where campaignid='".$campaignid."'";
//echo("
strsql : $strsql");
$result=mysql_query($strsql);
$recordcount = mysql_num_rows($result);
if($recordcount >0){
$line = mysql_fetch_array($result);
$url = $line["campaignurl"];
//echo "
campaignurl url : ".$url;
}
}
}
}
}
//echo("
url : ".$url);
if($url=="")
{
$url=$defaulturl."/default.php";
}
//echo("
substr : ".$url);
//echo("
substr : ".substr($url,0,1));
if(substr(trim($url),0,1)=="/")
{
$url=$host.$url;
}
//echo "
url : $url";
if($url == $host."/default.php")
{
$browserspecifichomepage = getBrowserSpecificHomePage();
$url=str_replace("default.php", $browserspecifichomepage, $url);
}
if(substr($url,0,7) !="http://")
{
$url = "http://".$url;
}
$url = $url."?hpg=$hpg_rga_cookie_values&useragent=$useragent";
//echo("
url : ".$url");
return $url;
}
//------------------------------------------------------------------------------
function getBrowserSpecificHomePage()
{
/*
Depricated ***
global $useragent;
$filename="home_ie.htm";
if(strpos($useragent,"mac" )>1)
{
$filename="defaultmac.htm";
}elseif(strpos($useragent,"4.7" )>1 || strpos($useragent,"Netscape/7.0" )>1)
{
$filename="home_ns.htm";
}
*/
$filename="default.php";
return $filename;
}
?>