📔PHP Postback Example
See some sample code for capturing postbacks on your server.
# PHP PDO Example
This an example of a plain PHP script handling Postbacks with a PDO database connection .
<?php
/**
* the Postbacks Section and the Postback Information heading.
*/
define('AdOffers_IP', '185.61.154.22'); // Note: as noted above change the IP to match what is in your affiliate panel.
$ip = $_SERVER['REMOTE_ADDR'];
// Connection Info
$DB_HOST = 'DB_HOST';
$DB_USER = 'DB_USER';
$DB_PASS = 'DB_PASS';
$DB_NAME = 'DB_DBNAME';
$DB_PORT = 3306;
/**
* Check the Remote Address is AdOffers
* if it is not throw an Exception
*/
if($ip !== AdOffers_IP)
{
// Process or Persist Data here inline or via a function call.
exit("0");
}
/**
*PDO DB Connection
*/
try{
$conn = new PDO("mysql:host={$DB_HOST}; port={$DB_PORT}; dbname={$DB_NAME}", $DB_USER, $DB_PASS);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
}catch(PDOException $err) {
exit($err->getMessage());
}
/**
* the parameter is getting passed by the URL Parameter By $_GET Request
*/
$subId = isset($_GET['user_id']) ? $_GET['user_id'] : null;
$offer_name = isset($_GET['offer_name']) ? $_GET['offer_name'] : null;
$offer_id = isset($_GET['offer_id']) ? $_GET['offer_id'] : null;
$reward = isset($_GET['amount']) ? $_GET['amount'] : null;
$payout = $_GET['payout'] ?? null;
if($user_id&& $offer_name && $offer_id && $amount) {
// Insert Query to Database Table
$query = "INSERT INTO transactions VALUES(NULL, '$user_id', '$offer_name', '$offer_id', '$amount', '$payout')";
if($conn->exec($query)) {
exit("1");
}else {
exit("0");
}
}else {
exit("0");
}
Last updated