<?php/**
* Redirect-Script
*
* Aufgabe:
* - Umgebungsdaten ermitteln
* -- Cookie gesetzt?
* -- Cookie übergeben?
*/
// definierte Werte die per se für mich gelten und von der Generator-Routine gesetzt werden
define('CustomerID', '254');
define('TagID', '586');
define('COOKIE_NAME', 'axd');
if (!defined('COOKIE_DOMAIN')) {
define('COOKIE_DOMAIN', '.theadex.com');
}
define('TS_DMPSTART', 1378591200);
function _schemaExplode($a) {
$ud = array();
while (list($k,$v) = each($a)) {
if (strpos($v, ':') > 0) {
list($Sub, $Time) = explode(":", $v);
$ud[$Sub] = $Time;
}
}
return $ud;
}
function _schemaImplode($a) {
$ud = array();
while (list($k, $time) = each($a)) {
$ud[] = $k.':'.$time;
}
return $ud;
}
/**
* Converts a timestamp to adex-days
*
* @param integer $timestamp
*
* @return integer
*/
function toAdexDays($timestamp) {
return floor(($timestamp - TS_DMPSTART) / (60*60*24));
}
/**
* Converts from adex days to a unix timestamp
*
* @param integer $AdexDays
*
* @return integer
*/
function fromAdexDays($AdexDays) {
return floor(TS_DMPSTART + ($AdexDays * 60*60*24));
}
/**
* Speichert zeitbezogene Zustandsdaten in einem Cookie - getrennt nach $key; separiert per | und :
* @param string $key SubIdentifier
* @param integer $days Gültigkeitsdauer
*
* @return boolean
*/
function stateInformationOlderThan($key, $days, $setState = false) {
$now = toAdexDays(time());
$expected = $now + $days;
$Cookie = 'tis';
$SubParts = array();
if (isset($_COOKIE[$Cookie])) {
// nach schema zerhacken
$parts = explode("|", $_COOKIE[$Cookie]);
$SubParts = _schemaExplode($parts);
if (isset($SubParts[$key]) && $SubParts[$key] * 1 > $now) {
return false;
}
}
if ($setState) {
$SubParts[$key] = $expected;
$implode = array();
$implode = _schemaImplode($SubParts);
setcookie($Cookie, join("|", $implode), fromAdexDays($now + 3000), '/', COOKIE_DOMAIN, false, false);
$_COOKIE[$Cookie] = join("|", $implode);
}
return true;
}
if (isset($_SERVER['QUERY_STRING'])) {
define("QS", substr($_SERVER['QUERY_STRING'], 0, 1) == '?' ? substr($_SERVER['QUERY_STRING'], 1) : $_SERVER['QUERY_STRING']);
} else {
define("QS", "");
}
if (isset($_GET['c']) && trim($_GET['c']) !== '') {
define('COOKIE', $_GET['c']);
} elseif (!empty($_COOKIE[COOKIE_NAME])) {
define('COOKIE', $_COOKIE[COOKIE_NAME]);
} else {
// kein Cookie, kein redirect
?>
<html><head></head><body></body></html>
<?php
exit;
}
$SSLon = false;
if (!empty($_SERVER['HTTPS'])) {
$SSLon = true;
}
if(isset($_SERVER['HTTP_X_PROTO']) && $_SERVER['HTTP_X_PROTO'] == 'SSL') {
$SSLon = true;
}
header('P3P:CP="CAO PSA OUR"');
ob_start();
if (!$SSLon) {
# no SSL
?>
<html>
<body>
<?php if (stateInformationOlderThan("EP8",7)) { ?>
<img width='1' height='1' src='http://cm.g.doubleclick.net/pixel?google_nid=theadex_dmp&google_cm&axd_cuid=254&c=<?= COOKIE ?>' />
<?php } ?>
</body>
</html>
<?php
} else {
# SSL
?>
<html>
<body>
<?php if (stateInformationOlderThan("EP8",7)) { ?>
<img width='1' height='1' src='https://cm.g.doubleclick.net/pixel?google_nid=theadex_dmp&google_cm&axd_cuid=254&c=<?= COOKIE ?>' />
<?php } ?>
</body>
</html>
<?php
}
ob_end_flush();