Advertisement
Guest User

WTF

a guest
May 25th, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.03 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Redirect-Script
  4.  *
  5.  * Aufgabe:
  6.  * - Umgebungsdaten ermitteln
  7.  * -- Cookie gesetzt?
  8.  * -- Cookie übergeben?
  9.  */
  10. // definierte Werte die per se für mich gelten und von der Generator-Routine gesetzt werden
  11. define('CustomerID', '323');
  12. define('TagID', '891');
  13.  
  14. define('COOKIE_NAME', 'axd');
  15.  
  16. if (!defined('COOKIE_DOMAIN')) {
  17.     define('COOKIE_DOMAIN', '.theadex.com');
  18. }
  19. define('TS_DMPSTART', 1378591200);
  20.  
  21. function _schemaExplode($a) {
  22.     $ud = array();
  23.     while (list($k,$v) = each($a)) {
  24.         if (strpos($v, ':') > 0) {
  25.             list($Sub, $Time) = explode(":", $v);
  26.             $ud[$Sub] = $Time;
  27.         }
  28.     }
  29.     return $ud;
  30. }
  31.  
  32. function _schemaImplode($a) {
  33.     $ud = array();
  34.     while (list($k, $time) = each($a)) {
  35.         $ud[] = $k.':'.$time;
  36.     }
  37.     return $ud;
  38. }
  39.  
  40. /**
  41.  * Converts a timestamp to adex-days
  42.  *
  43.  * @param integer $timestamp
  44.  *
  45.  * @return integer
  46.  */
  47. function toAdexDays($timestamp) {
  48.     return floor(($timestamp - TS_DMPSTART) / (60*60*24));
  49. }
  50.  
  51. /**
  52.  * Converts from adex days to a unix timestamp
  53.  *
  54.  * @param integer $AdexDays
  55.  *
  56.  * @return integer
  57.  */
  58. function fromAdexDays($AdexDays) {
  59.     return floor(TS_DMPSTART + ($AdexDays * 60*60*24));
  60. }
  61.  
  62. /**
  63.  * Speichert zeitbezogene Zustandsdaten in einem Cookie - getrennt nach $key; separiert per | und :
  64.  * @param string  $key  SubIdentifier
  65.  * @param integer $days Gültigkeitsdauer
  66.  *
  67.  * @return boolean
  68.  */
  69. function stateInformationOlderThan($key, $days, $setState = false) {
  70.     $now = toAdexDays(time());
  71.     $expected = $now  + $days;
  72.     $Cookie = 'tis';
  73.     $SubParts = array();
  74.     if (isset($_COOKIE[$Cookie])) {
  75.         // nach schema zerhacken
  76.         $parts = explode("|", $_COOKIE[$Cookie]);
  77.         $SubParts = _schemaExplode($parts);
  78.  
  79.         if (isset($SubParts[$key]) && $SubParts[$key] * 1 > $now) {
  80.             return false;
  81.         }
  82.     }
  83.  
  84.     if ($setState) {
  85.         $SubParts[$key] = $expected;
  86.  
  87.         $implode = array();
  88.         $implode = _schemaImplode($SubParts);
  89.         setcookie($Cookie, join("|", $implode), fromAdexDays($now + 3000), '/', COOKIE_DOMAIN, false, false);
  90.         $_COOKIE[$Cookie] = join("|", $implode);
  91.     }
  92.  
  93.     return true;
  94. }
  95.  
  96. if (isset($_SERVER['QUERY_STRING'])) {
  97.     define("QS", substr($_SERVER['QUERY_STRING'], 0, 1) == '?' ? substr($_SERVER['QUERY_STRING'], 1) : $_SERVER['QUERY_STRING']);
  98. } else {
  99.     define("QS", "");
  100. }
  101.  
  102. if (isset($_GET['c']) && trim($_GET['c']) !== '') {
  103.     define('COOKIE', $_GET['c']);
  104. } elseif (!empty($_COOKIE[COOKIE_NAME])) {
  105.     define('COOKIE', $_COOKIE[COOKIE_NAME]);
  106. } else {
  107.     // kein Cookie, kein redirect
  108.     ?>
  109.     <html><head></head><body></body></html>
  110.     <?php
  111.     exit;
  112. }
  113.  
  114. $SSLon = false;
  115. if (!empty($_SERVER['HTTPS'])) {
  116.     $SSLon = true;
  117. }
  118.  
  119. if(isset($_SERVER['HTTP_X_PROTO']) && $_SERVER['HTTP_X_PROTO'] == 'SSL') {
  120.     $SSLon = true;
  121. }
  122.  
  123. header('P3P:CP="CAO PSA OUR"');
  124. ob_start();
  125. if (!$SSLon) {
  126.     # no SSL
  127.    ?>
  128.     <html>
  129.         <body>
  130.             <?php if (stateInformationOlderThan("EP2",7)) { ?>
  131. <img width='1' height='1' src='http://c1.adform.net/serving/cookie/match/?party=1010&adx_id=323' />
  132. <?php } ?>
  133. <?php if (stateInformationOlderThan("EP14",7)) { ?>
  134. <img width='1' height='1' src='http://dsp.adfarm1.adition.com/cookie/?redirect=http%3A%2F%2Fdmp.theadex.com%2Fd%2F323%2Fi%2F2.gif%3Fc%3D<?= COOKIE ?>%26axd_pid%3D14%26axd_fuid%3D%25%25COOKIE%25%25' />
  135. <?php } ?>
  136.         </body>
  137.     </html>
  138.     <?php
  139. } else {
  140.     # SSL
  141.    ?>
  142.     <html>
  143.         <body>
  144.             <?php if (stateInformationOlderThan("EP2",7)) { ?>
  145. <img width='1' height='1' src='https://c1.adform.net/serving/cookie/match/?party=1010&adx_id=323' />
  146. <?php } ?>
  147. <?php if (stateInformationOlderThan("EP14",7)) { ?>
  148. <img width='1' height='1' src='https://dsp.adfarm1.adition.com/cookie/?redirect=https%3A%2F%2Fdmp.theadex.com%2Fd%2F323%2Fi%2F2.gif%3Fc%3D<?= COOKIE ?>%26axd_pid%3D14%26axd_fuid%3D%25%25COOKIE%25%25' />
  149. <?php } ?>
  150.         </body>
  151.     </html>
  152.     <?php
  153. }
  154. ob_end_flush();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement