1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CPA Postback Help

Discussion in 'PHP & Perl' started by somebodysomewhere, Aug 25, 2014.

  1. somebodysomewhere

    somebodysomewhere Junior Member

    Joined:
    Feb 24, 2008
    Messages:
    171
    Likes Received:
    66
    Location:
    USA
    Home Page:
    I bought a site template that implements various CPA networks for a GPT site. The setup is pretty much done, I'm able to generate my own offer walls and the like, however this is my first go with postbacks (I know I know, I'm super lame). I have some postback files with what look to be the right variables, I've plugged in my info however the postback url is not generating or the script is not updating the sql databae. IE myself or a member completes a survey or what have you but they don't get the points for it. I'd really appreciate any help from anyone who knows about this, I'm really not just looking to pay to have it done, I need help understanding what is or is not being generated and why.
     
  2. Nitros

    Nitros Power Member

    Joined:
    Jan 30, 2009
    Messages:
    573
    Likes Received:
    295
    Postback is pretty simple. When you upload script on your server that is responsbile for sending queries to the database you need to copy and paste its address (ex. http://yourdomain.com/postback.php) on the cpa network you are using.

    It works like this: Someone completed an offer->CPA network is sending data about user who completed it (IP, subid, etc.) to your script (postback.php) using GET variables -> Your script saves them to database.

    you can check if your postback script is working by loading its full address (with variables) in your web browser.
    It should look like this for example: http://yourdomain.com/postback.php?subid=testuser
     
    • Thanks Thanks x 1
  3. lord1027

    lord1027 Elite Member

    Joined:
    Sep 20, 2013
    Messages:
    3,174
    Likes Received:
    2,222
    Is your website bucksfly? I see you're promoting it in your signature.
     
  4. somebodysomewhere

    somebodysomewhere Junior Member

    Joined:
    Feb 24, 2008
    Messages:
    171
    Likes Received:
    66
    Location:
    USA
    Home Page:
    Not this project, but yes. I moved servers and I need to set up that domain again too.
     
  5. razorsa

    razorsa Newbie

    Joined:
    Aug 25, 2014
    Messages:
    12
    Likes Received:
    2
    I would modify the script to force it to log the fact that it was accessed first, once you figure out if its actually being called it will make it alot easier to solve
     
  6. somebodysomewhere

    somebodysomewhere Junior Member

    Joined:
    Feb 24, 2008
    Messages:
    171
    Likes Received:
    66
    Location:
    USA
    Home Page:
    Thanks Nitros, I get the general idea. I suppose the only way to get to brass tacks is post the code. Here's the offerwall code:

    Code:
    <iframe src="https://www.somepointscurrency.com/super/offers?h=networkvar.number3&uid=<?PHP echo $_SESSION['uid']; ?>&color=0068B3&rot_time=15&qcolor=036163" frameborder="0" width="728" height="2400" scrolling="no"></iframe>
    then this for the postback file

    Code:
    <?php
    
    require_once($_SERVER['DOCUMENT_ROOT']."/includes/includes.inc.php");
    
    require_once($_SERVER['DOCUMENT_ROOT']."/includes/postback.functions.inc.php");
    
    require_once($_SERVER['DOCUMENT_ROOT']."/includes/postback.logging.inc.php");
    
    
    
    //Setting initial variables
    
    $secret_key = 'mysecretapkey'; //Enter secret key here
    
    $user_id = $_REQUEST['uid'];
    
    $user_name = ScrapeDB('username', $user_id, 0);
    
    $external_hash = $_REQUEST['sig'];
    
    $transaction_id = $_REQUEST['id'];
    
    $points_earned = $_REQUEST['new'];
    
    
    
    
    
    //Security check to verify real postback
    
    $local_hash_calc = md5($transaction_id . ':' . $points_earned . ':' . $user_id . ':' . $secret_key);
    
    
    
    if(($local_hash_calc == $external_hash) && (CheckForUniqueSID($user_id, $transaction_id) == 0)) {
    
    	$user_id = ScrapeDB('id', $user_name, 0);
    
    	$referral_id = ScrapeDB('referral_ID', $user_name, 0);
    
    	$referral_name = ScrapeDB('username', $referral_id, 1);
    
    	
    
    	$referral_points_earned = CalcReferralPoints($points_earned, $referral_id);
    
    
    
    	//Update User Points
    
    	UpdateUserPoints($points_earned, $user_name, 0);
    
    	UpdateReferralPoints($referral_points_earned, $referral_id, $user_id);
    
    
    
    	$total_user_points = ScrapeDB('points', $user_name);	
    
    	$total_referral_points = ScrapeDB('points', $referral_id, '1');
    
    	
    
    	WriteLogsToDB($user_name,
    
    			$user_id, 
    
    			$points_earned, 
    
    			$total_user_points, 
    
    			$referral_name, 
    
    			$referral_id,
    
    			$referral_points_earned, 
    
    			$total_referral_points, 
    
    			's-rewards',
    
    			$transaction_id);
    
    	
    
    	echo "1";// if user is credited successfully else echo 0
    
    } else if (CheckForUniqueSID($user_id, $transaction_id) >= 1){
    
    	echo "1";
    
    }else{
    
    	echo "0";
    
    }
    
    ?>
    
     
  7. somebodysomewhere

    somebodysomewhere Junior Member

    Joined:
    Feb 24, 2008
    Messages:
    171
    Likes Received:
    66
    Location:
    USA
    Home Page:
    When I plug in just the postback url it just gives me the 1 or 0 saying it worked or not, it says it did but the points never get credited. Do I have to echo out everything and step through it to pinpoint?
     
  8. Nitros

    Nitros Power Member

    Joined:
    Jan 30, 2009
    Messages:
    573
    Likes Received:
    295
    I see in your code that it will echo saying 1 in two situations. First when data is saved to the database:
    and second when function "CheckForUniqueSID" is used:

    so I'm guessing it is saying 1 because of CheckForUniqueSID.

    As your string(sent to "uid" by GET) is encoded for security reasons I suggest first checking if it is getting all these variables ($user_name,$user_id, etc.) right by printing them instead of saving to database.
     
    • Thanks Thanks x 1