Question about executing a script on another domain php?

superaff1984

Senior Member
Premium Member
Joined
Jun 16, 2010
Messages
992
Reaction score
131
We have a what's called a postback file that sends conversions back to Facebook and other advertising networks. However, I want a postback to be sent to Facebook, but I don't want them to know the domain that is sending the postback. I have a file on www.secretdomain.com/postback.php. I then have the Facebook conversion pixel on www.facebookpixel.com/postback.php.

What's the best way to include the file from www.facebookpixel.com/postback.php into our www.secretdomain.com/postback.php? So when the conversion is sent back Facebook will think it's the www.facebookpixel.com/postback.php sent it in vs our secret domain?

I was thinking adding PHP fopen ? Or would this not work?
 
fopen will be difficult, because while it can send a HTTP request, setting headers/referrals et al can be problematic.

The simplest solution would be to use cURL

Here's a basic implementation of a Pixel Proxy - of course please test it thoroughly

PHP:
<?php
// This is the script that lives on secretdomain.com/postback.php

// 1. Initialize cURL
$ch = curl_init();

// 2. Get all parameters from the conversion
// For example, if conversion sends: secretdomain.com/postback.php?transaction_id=123&amount=50
$query = http_build_query($_GET);  // This captures ALL parameters automatically

// 3. Setup the cURL request to facebookpixel.com
curl_setopt($ch, CURLOPT_URL, 'http://www.facebookpixel.com/postback.php?' . $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.facebookpixel.com');  // Makes it look like it came from facebookpixel.com

// 4. Execute the request
$response = curl_exec($ch);

// 5. Output the response
echo $response;

// 6. Close cURL
curl_close($ch);
?>

This will

- Grab the pixel parameters (transaction_id=123)
- Make a cURL request to facebookpixel.com
- Forward those same parameters
- Make it look like it came from facebookpixel.com
 
fopen will be difficult, because while it can send a HTTP request, setting headers/referrals et al can be problematic.

The simplest solution would be to use cURL

Here's a basic implementation of a Pixel Proxy - of course please test it thoroughly

PHP:
<?php
// This is the script that lives on secretdomain.com/postback.php

// 1. Initialize cURL
$ch = curl_init();

// 2. Get all parameters from the conversion
// For example, if conversion sends: secretdomain.com/postback.php?transaction_id=123&amount=50
$query = http_build_query($_GET);  // This captures ALL parameters automatically

// 3. Setup the cURL request to facebookpixel.com
curl_setopt($ch, CURLOPT_URL, 'http://www.facebookpixel.com/postback.php?' . $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.facebookpixel.com');  // Makes it look like it came from facebookpixel.com

// 4. Execute the request
$response = curl_exec($ch);

// 5. Output the response
echo $response;

// 6. Close cURL
curl_close($ch);
?>

This will

- Grab the pixel parameters (transaction_id=123)
- Make a cURL request to facebookpixel.com
- Forward those same parameters
- Make it look like it came from facebookpixel.com

Thanks, I was thinking curl too. However, I don't think the $query will be necessary, but thanks for letting me know. As we won't be passing anything. We just need the basic facebook pixel to execute, but making sure it says it came from facebookpixel.com. Hopefully this works. I tried sharing the Facebook pixel below, but it would not let me for some reason.
 
Thanks, I was thinking curl too. However, I don't think the $query will be necessary, but thanks for letting me know. As we won't be passing anything. We just need the basic facebook pixel to execute, but making sure it says it came from facebookpixel.com. Hopefully this works. I tried sharing the Facebook pixel below, but it would not let me for some reason.

Of course, the $query is there for when you have params being posted to the postback.

Let me know how it works or if you need anymore help.
 
Of course, the $query is there for when you have params being posted to the postback.

Let me know how it works or if you need anymore help.

I tried this code, it's returning to Facebook, but it's returning our domain we want to hide.
 
Back
Top