Use Simple PHP to Receive Postbacks from CPA Networks

In a previous tutorial, I taught you guys how you could redirect the traffic based on its location. In this one, I’m going to explain how you can receive PostBacks from CPA network and use their data to increase your CPA income. Without further ado, let’s start.

Step 1 | Creating the PostBack URL

To create the PostBacks file, you should first make sure the parameters that you are going to use. Every CPA network provides a list of macros that could be used to provide data to your PostBacks PHP file. Go over to your CPA network, in this case AdGateMedia, and click the PostBacks tab.

You will see a bunch of macros with their usage options, and you’ll find this data in most of the CPA networks, at least the ones I know have it. For Example, the macro {payout} represents the payout on an offer and will provide you with that detail every time a lead occurs. There will also be a Sample URL which we will use in the later steps.

So, let’s say we want 5 parameters:

  • Offer ID represented by the macro {offer_id}
  • Offer Name represented by the macro {offer_name}
  • The IP of the User represented by the macro {session_ip}
  • Date and Time When the Lead Occurred represented by the macro {datetime}
  • Payout of the Lead represented by the macro {payout}


Assuming that you will upload the PHP file (let’s name it adgatepostback.php) in the root of your domain, the resultant PostBack URL will be:{offer_id}&data2={offer_name}&data3={session_ip}& data4={datetime}&data5={payout}


Do not add the URL now as we have neither created nor uploaded the file onto our server. For doing that, let’s step forward to Step 2.

Step 2 | Creating the PostBack PHP File

Create a new file and paste the code below and upload it to your hosting. Also, after creating the file, add the URL to your CPA network as a GLOBAL PostBack link.




$currenttime = date(‘m/d/Y h:i:s’);


//Get the data from the URL

if(isset($_GET[“data”]) && isset($_GET[“data2”]) && isset($_GET[“data3”]) && isset($_GET[“data4”]) && isset($_GET[“data5”]))


    $data = $_GET[“data”];

    $data2 = $_GET[“data2”];

                $data3 = $_GET[“data3”];

                $data4 = $_GET[“data4”];

                $data5 = $_GET[“data5”];



// Write to file

$myfile = fopen(“adgatelogs.txt”, “a”) or die(“Unable to open file!”);

$txt = $data.”,”.$data2.”,”.$data3.”,”.$data4.”,”.$data5.”,”.$currenttime;

fwrite($myfile, “n”. $txt);





It will create a file “adgatelogs.txt” in the same place as your PHP file, and the output can be seen in the next step.

Step 3 | Using the data

You will receive the data in the following format keeping that you used the same variables as stated in this tutorial.

Adding more variables such as subids will increase your chances in getting more from this data since by using them you can identify the source of the traffic and therefore target more accurately than at present.







Hakunamatata! Rpkrocks is here to share and offer valuable services.

Recent Posts