Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.97 KB | None | 0 0
  1. <?
  2. /* Get Variable Pass-thru Mod, by Mark -- http://ctrtard.com -- added 8-3-2010
  3. This mod will allow you to pass additional variables to the P202 redirect. E.g.
  4. $tracking202outbound = 'http://your202.com/tracking202/redirect/off.php?acip=123&pci='.$_COOKIE['tracking202pci'] . '&zip=10010';
  5. */
  6. $stack ="";
  7. foreach($_GET as $key => $value) {
  8.     if ($key != "acip" AND $key != "pci"){
  9.     $stack .= "&$key=" . urlencode($value);
  10.     }
  11. }
  12. /* End Get Variable Pass-thru Mod */
  13.  
  14. #only allow numeric acip's
  15. $acip = $_GET['acip'];
  16. if (!is_numeric($acip)) die();
  17.  
  18. #cached redirects stored here:
  19. $myFile = "cached/off-cached.csv";
  20.  
  21.  
  22. # check to see if mysql connection works, if not fail over to cached .CSV stored redirect urls
  23. include_once($_SERVER['DOCUMENT_ROOT'] . '/202-config.php');
  24.  
  25. $usedCachedRedirect = false;
  26. $dbconnect = @mysql_connect($dbhost,$dbuser,$dbpass);
  27. if (!$dbconnect) $usedCachedRedirect = true;
  28.  
  29. if ($usedCachedRedirect==false) $dbselect = @mysql_select_db($dbname);
  30. if (!$dbselect) $usedCachedRedirect = true;
  31.  
  32. #the mysql server is down, use the txt cached redirect
  33. if ($usedCachedRedirect==true) {
  34.  
  35.     $handle = @fopen($myFile, 'r');
  36.     while ($row = @fgetcsv($handle, 100000, ",")) {
  37.        
  38.         //if a cached key is found for this t202id, redirect to that url
  39.         if ($row[0] == $acip) {
  40.             header('location: '. $row[1]);
  41.             die();
  42.         }
  43.     }
  44.     @fclose($handle);
  45.    
  46.     die("<h2>Error establishing a database connection - please contact the webhost</h2>");
  47. }
  48.  
  49.  
  50. include_once($_SERVER['DOCUMENT_ROOT'] . '/202-config/connect2.php');
  51.  
  52. /* OK FIRST IF THERE IS NO PUBLIC CLICK_ID, JUST REDIRECT TO THE NORMAL CAMPAIGN */
  53. if (!$_GET['pci']) {
  54.  
  55.     $mysql['aff_campaign_id_public'] = mysql_real_escape_string($acip);
  56.     $aff_campaign_sql = "SELECT   aff_campaign_rotate,
  57.                                     aff_campaign_url,
  58.                                     aff_campaign_url_2,
  59.                                     aff_campaign_url_3,
  60.                                     aff_campaign_url_4,
  61.                                     aff_campaign_url_5,
  62.                                     aff_campaign_name,
  63.                                     aff_campaign_cloaking
  64.                             FROM    202_aff_campaigns
  65.                             WHERE   aff_campaign_id_public='".$mysql['aff_campaign_id_public']."'";
  66.     $aff_campaign_row = memcache_mysql_fetch_assoc($aff_campaign_sql);
  67.    
  68.     if (empty($aff_campaign_row['aff_campaign_url'])) { die(); } //if there is no aff_url to redirect to DIEEEEEE!!!!!!! EEEEEE!!!
  69.  
  70.     #cache the results
  71.     if ( is_writable(dirname(__FILE__) . '/cached' )) {
  72.    
  73.         #if the file does not exist create it
  74.         if (!file_exists($myFile)) {
  75.             $handle = @fopen($myFile, 'w');
  76.             @fclose($handle);
  77.         }
  78.        
  79.         # now save this link to the
  80.         $handle = @fopen($myFile, 'r');
  81.         $writeNewIndex = true;
  82.         while (($row = @fgetcsv($handle, 100000, ",")) and ($writeNewIndex == true)) {
  83.             if ($row[0] == $acip) $writeNewIndex = false;
  84.         }
  85.         @fclose($handle);
  86.        
  87.         if ($writeNewIndex) {
  88.             //write this index to the txt file
  89.             $newLine = "$acip, {$aff_campaign_row['aff_campaign_url']} \n";
  90.             $newHandle = @fopen($myFile, 'a+');
  91.             @fwrite($newHandle, $newLine);
  92.             @fclose($newHandle);
  93.         }
  94.     }
  95.    
  96.     $redirect_site_url = rotateTrackerUrl($aff_campaign_row);
  97.     //$redirect_site_url = $redirect_site_url . $click_id;
  98.     $redirect_site_url = replaceTrackerPlaceholders($redirect_site_url,$click_id);
  99.    
  100.     /* Get Variable Pass-thru Mod */
  101.     $redirect_site_url .= $stack;
  102.     /* End Variable Pass-thru Mod */
  103.  
  104.     //ok if there is a url that exists, if redirect php style, or if its cloaked, redirect meta refresh style.
  105.     if ($aff_campaign_row['aff_campaign_cloaking'] == 0) {
  106.        
  107.         //cloaking OFF, so do a php header redirect
  108.         header('location: '.$redirect_site_url);
  109.    
  110.     } else {
  111.        
  112.         //cloaking ON, so do a meta REFRESH
  113.         $html['aff_campaign_name'] = $aff_campaign_row['aff_campaign_name']; ?>
  114.  
  115.         <html>
  116.             <head>
  117.                 <title><? echo $html['aff_campaign_name']; ?></title>
  118.                 <meta name="robots" content="noindex">
  119.                 <meta http-equiv="refresh" content="1; url=<? echo $redirect_site_url; ?>">
  120.             </head>
  121.             <body>
  122.            
  123.             <form name="form1" id="form1" method="get" action="/tracking202/redirect/cl2.php">
  124.                 <input type="hidden" name="q" value="<? echo $redirect_site_url; ?>"/>
  125.             </form>
  126.                 <script type="text/javascript">
  127.                     document.form1.submit();
  128.                 </script>
  129.        
  130.                 <div style="padding: 30px; text-align: center;">
  131.                     You are being automatically redirected to <? echo $html['aff_campaign_name']; ?>.<br/><br/>
  132.                     Page Stuck? <a href="<? echo $redirect_site_url; ?>">Click Here</a>.
  133.                 </div>
  134.             </body>
  135.         </html>
  136.  
  137.  <? }
  138.    
  139.     //terminate this script, this is the end, if there was no public_click_id
  140.     die();
  141. }
  142.  
  143.  
  144.  
  145. /* ------------------------------------------------------- */
  146. /* ------------------------------------------------------- */
  147. /* ------------------------------------------------------- */
  148. //
  149. //
  150. //
  151. //  ANYTHING BELOW THIS ASSUMES THERE IS A PUBLIC CLICK ID
  152. //
  153. //
  154. /* ------------------------------------------------------- */
  155. /* ------------------------------------------------------- */
  156. /* ------------------------------------------------------- */
  157.  
  158.  
  159. $mysql['aff_campaign_id_public'] = mysql_real_escape_string($_GET['acip']);
  160. $mysql['click_id_public'] = mysql_real_escape_string($_GET['pci']);
  161.  
  162. $info_sql = "
  163.     SELECT
  164.         2c.click_id,
  165.         2c.user_id,
  166.         click_filtered,
  167.         landing_page_id,
  168.         click_cloaking,
  169.         click_cloaking_site_url_id,
  170.         click_redirect_site_url_id,
  171.         2ac.aff_campaign_id,
  172.         aff_campaign_rotate,
  173.         aff_campaign_url,
  174.         aff_campaign_url_2,
  175.         aff_campaign_url_3,
  176.         aff_campaign_url_4,
  177.         aff_campaign_url_5,
  178.         aff_campaign_name,
  179.         aff_campaign_cloaking,
  180.         aff_campaign_payout
  181.     FROM
  182.         202_aff_campaigns AS 2ac,
  183.         202_clicks_record AS 2cr
  184.         LEFT JOIN 202_clicks AS 2c ON (2c.click_id = 2cr.click_id)
  185.         LEFT JOIN 202_clicks_site AS 2cs ON (2cs.click_id = 2cr.click_id)
  186.     WHERE
  187.         2ac.aff_campaign_id_public='".$mysql['aff_campaign_id_public']."'
  188.         AND 2cr.click_id_public='".$mysql['click_id_public']."'
  189. ";
  190. $info_row = memcache_mysql_fetch_assoc($info_sql);
  191.  
  192.  
  193.  
  194.  
  195. #cache the results
  196. if ( is_writable(dirname(__FILE__) . '/cached' )) {
  197.  
  198.     #if the file does not exist create it
  199.     if (!file_exists($myFile)) {
  200.         $handle = @fopen($myFile, 'w');
  201.         @fclose($handle);
  202.     }
  203.    
  204.     # now save this link to the
  205.     $handle = @fopen($myFile, 'r');
  206.     $writeNewIndex = true;
  207.     while (($row = @fgetcsv($handle, 100000, ",")) and ($writeNewIndex == true)) {
  208.         if ($row[0] == $acip) $writeNewIndex = false;
  209.     }
  210.     @fclose($handle);
  211.    
  212.     if ($writeNewIndex) {
  213.         //write this index to the txt file
  214.         $newLine = "$acip, {$info_row['aff_campaign_url']} \n";
  215.         $newHandle = @fopen($myFile, 'a+');
  216.         @fwrite($newHandle, $newLine);
  217.         @fclose($newHandle);
  218.     }
  219. }
  220.    
  221.    
  222.  
  223.  
  224.  
  225. $click_id = $info_row['click_id'];
  226. $mysql['click_id'] = mysql_real_escape_string($click_id);
  227. /****** THESES ARE THE VARIABLES I NEED TO UPDATE TO THE PUBLIC_CLICK_ID *********/
  228.  
  229. // click spy & clicks
  230. //  aff_campaign_id
  231. //  click_payout
  232.  
  233. $mysql['aff_campaign_id'] = mysql_real_escape_string($info_row['aff_campaign_id']);
  234. $mysql['click_payout'] = mysql_real_escape_string($info_row['aff_campaign_payout']);
  235.  
  236. $update_sql = "
  237.     UPDATE
  238.         202_clicks AS 2c
  239.         LEFT JOIN 202_clicks_spy AS 2cs ON (2c.click_id = 2cs.click_id)
  240.     SET
  241.         2c.aff_campaign_id='".$mysql['aff_campaign_id']."',
  242.         2cs.aff_campaign_id='".$mysql['aff_campaign_id']."',
  243.         2c.click_payout='".$mysql['click_payout']."',
  244.         2cs.click_payout='".$mysql['click_payout']."'
  245.     WHERE
  246.         2c.click_id='".$mysql['click_id']."'
  247. ";
  248. //this function delays the sql, because UPDATING is very very slow
  249. delay_sql($update_sql);
  250.  
  251. //clicks_record
  252. //  click_cloaking
  253. //  click_out
  254.  
  255. $mysql['click_out'] = 1;
  256.  
  257. if (($info_row['click_cloaking'] == 1) or //if tracker has overrided cloaking on                                                            
  258.     (($info_row['click_cloaking'] == -1) and ($info_row['aff_campaign_cloaking'] == 1)) or
  259.     ((!isset($info_row['click_cloaking'])) and ($info_row['aff_campaign_cloaking'] == 1)) //if no tracker but but by default campaign has cloaking on
  260. ) {
  261.     $cloaking_on = true;
  262.     $mysql['click_cloaking'] = 1;
  263.     //if cloaking is on, add in a click_id_public, because we will be forwarding them to a cloaked /cl/xxxx link
  264. } else {
  265.     $mysql['click_cloaking'] = 0;
  266. }
  267.  
  268. $update_sql = "
  269.     UPDATE
  270.         202_clicks_record
  271.     SET
  272.         click_out='".$mysql['click_out']."',
  273.         click_cloaking='".$mysql['click_cloaking']."'
  274.     WHERE
  275.         click_id='".$mysql['click_id']."'
  276. ";
  277. delay_sql($update_sql);
  278.  
  279.  
  280. //clicks_site
  281. //  click_outbound_site_url_id='".$mysql['click_outbound_site_url_id']."',
  282. //  click_cloaking_site_url_id='".$mysql['click_cloaking_site_url_id']."',
  283. //  click_redirect_site_url_id='".$mysql['click_redirect_site_url_id']."'";
  284.  
  285. $outbound_site_url = 'http://'.$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
  286. $click_outbound_site_url_id = INDEXES::get_site_url_id($outbound_site_url);
  287. $mysql['click_outbound_site_url_id'] = mysql_real_escape_string($click_outbound_site_url_id);
  288.  
  289. if ($cloaking_on == true) {
  290.     $cloaking_site_url = 'http://'.$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
  291. }
  292.  
  293.  
  294. $redirect_site_url = rotateTrackerUrl($info_row);
  295. //$redirect_site_url = $redirect_site_url . $click_id;
  296. $redirect_site_url = replaceTrackerPlaceholders($redirect_site_url,$click_id);
  297.  
  298. $click_redirect_site_url_id = INDEXES::get_site_url_id($redirect_site_url);
  299. $mysql['click_redirect_site_url_id'] = mysql_real_escape_string($click_redirect_site_url_id);
  300.  
  301. $update_sql = "
  302.     UPDATE
  303.         202_clicks_site
  304.     SET
  305.         click_outbound_site_url_id='".$mysql['click_outbound_site_url_id']."',
  306.         click_redirect_site_url_id='".$mysql['click_redirect_site_url_id']."'
  307.     WHERE
  308.         click_id='".$mysql['click_id']."'
  309. ";
  310. delay_sql($update_sql);
  311.  
  312.  
  313. //alright now the updates,
  314. //WE WANT TO DELAY THESES UPDATES, in a MYSQL DATBASES? Or else the UPDATES lag the server, the UPDATES have to wait until it locks to update the server
  315. //so what happens is if there not delayed, if someone is pulling MASSIVE queries on the t202 website, it'll wait till they load before our update runs,
  316. //and that means if this update wasn't delayed it'd wait untill their queries were done on the site before moving forward.  Massive slowness, so we update delays theses in  cronjobs a at a lter time.
  317.  
  318.  
  319. //ADD TO CLICK SUMMARY TABLE?
  320.  
  321. //update the click summary table if this is a 'real click'
  322. #if ($info_row['click_filtered'] == 0) {
  323.    
  324.     $mysql['landing_page_id'] = mysql_real_escape_string($info_row['landing_page_id']);
  325.     $mysql['user_id'] = mysql_real_escape_string($info_row['user_id']);
  326.    
  327.     //set timezone correctly
  328.     $user_sql = "SELECT user_timezone FROM 202_users WHERE user_id='".$mysql['user_id']."'";
  329.     $user_row = memcache_mysql_fetch_assoc($user_sql); 
  330.     AUTH::set_timezone($user_row['user_timezone']);
  331.  
  332.  
  333.     $now = time();
  334.  
  335.     $today_day = date('j', time());
  336.     $today_month = date('n', time());
  337.     $today_year = date('Y', time());
  338.  
  339.     //the click_time is recorded in the middle of the day
  340.     $click_time = mktime(12,0,0,$today_month,$today_day,$today_year);
  341.     $mysql['click_time'] = mysql_real_escape_string($click_time);
  342.  
  343.     //check to make sure this click_summary doesn't already exist
  344.     $check_sql = "SELECT  COUNT(*)
  345.                   FROM    202_summary_overview
  346.                   WHERE user_id='".$mysql['user_id']."'
  347.                   AND     landing_page_id='".$mysql['landing_page_id']."'
  348.                   AND     aff_campaign_id='".$mysql['aff_campaign_id']."'
  349.                   AND     click_time='".$mysql['click_time']."'";
  350.     $check_result = mysql_query($check_sql) or record_mysql_error($check_sql);
  351.     $check_count = mysql_result($check_result,0,0);      
  352.  
  353.     //if this click summary hasn't been recorded do this now
  354.     if ($check_count == 0 ) {
  355.  
  356.         $insert_sql = "INSERT INTO 202_summary_overview
  357.                         SET         user_id='".$mysql['user_id']."',
  358.                                    landing_page_id='".$mysql['landing_page_id']."',
  359.                                    aff_campaign_id='".$mysql['aff_campaign_id']."',
  360.                                    click_time='".$mysql['click_time']."'";
  361.         $insert_result = mysql_query($insert_sql);
  362.     }  
  363. #}
  364.  
  365. //set the cookie
  366. setClickIdCookie($mysql['click_id'],$mysql['aff_campaign_id']);
  367.  
  368. //NOW LETS REDIRECT
  369.  
  370. /* Get Variable Pass-thru Mod */
  371. $redirect_site_url .= $stack;
  372. /* End Variable Pass-thru Mod */
  373.  
  374. if ($cloaking_on == true) {
  375.  
  376.     //if cloaking is turned on, meta refresh out
  377.    
  378. ?> <html>
  379.     <head>
  380.         <title><? echo $html['aff_campaign_name']; ?></title>
  381.         <meta name="robots" content="noindex">
  382.         <meta http-equiv="refresh" content="1; url=<? echo $redirect_site_url; ?>">
  383.     </head>
  384.     <body>
  385.    
  386.         <form name="form1" id="form1" method="get" action="/tracking202/redirect/cl2.php">
  387.             <input type="hidden" name="q" value="<? echo $redirect_site_url; ?>"/>
  388.         </form>
  389.         <script type="text/javascript">
  390.             document.form1.submit();
  391.         </script>
  392.        
  393.         <div style="padding: 30px; text-align: center;">
  394.             You are being automatically redirected to <? echo $html['aff_campaign_name']; ?>.<br/><br/>
  395.             Page Stuck? <a href="<? echo $redirect_site_url; ?>">Click Here</a>.
  396.         </div>
  397.     </body>
  398. </html>
  399. <? } else {
  400.    
  401.     //if cloaking is turned off, php header redirect out
  402.     header('location: '.$redirect_site_url);
  403.    
  404. }
  405.  
  406. die();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement