Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * This is a PayPal IPN (Instant Payment Notification) broadcaster
- * Since PayPal does not provide any straightforward way to add
- * multiple IPN listeners we'll have to create a central IPN
- * listener that will broadcast (or filter and dispatch) Instant
- * Payment Notifications to different destinations (IPN listeners)
- *
- * Destination IPN listeners must not panic and recognize IPNs sent
- * by this central broadcast as valid ones in terms of source IP
- * and any other fingerprints. Any IP filtering must add this host,
- * other adjustments made as necessary.
- *
- * IPNs are logged into files for debugging and maintenance purposes
- *
- * this code comes with absolutely no warranty
- * http://codeseekah.com/2012/02/11/how-to-setup-multiple-ipn-receivers-in-paypal/
- *
- * This modification checks the receiver_email field to decide on where to broadcast
- * The broadcast has been modified from curl to a 302 redirect
- */
- ini_set( 'max_execution_time', 0 ); /* Do not abort with timeouts */
- ini_set( 'display_errors', 'Off' ); /* Do not display any errors to anyone */
- $urls = array(); /* The broadcast session queue */
- /* List of IPN listener points */
- $ipns = array(
- 'store1' => 'http://store1.com/ipn.php',
- 'store2' => 'http://store2.com/paypal_ipn.php',
- 'store3' => 'http://store3.com/paypal/ipn.php'
- );
- $emais = array(
- 'store1' => 'store1@gmail.com',
- 'store2' => 'store2@yahoo.com',
- 'store3' => 'store3@hotmail.com'
- );
- /* Fingerprints */
- if ( /* My Store IPN Fingerprint */
- $_POST["receiver_email"] == $emails['store1']
- header("HTTP/1.1 302 Moved Temporarily");
- header("Location: $ipns['store1']");
- ) urls []= $ipns['store1'];
- if ( /* My Other Store IPN Fingerprint */
- $_POST["receiver_email"] == $emails['store2']
- header("HTTP/1.1 302 Moved Temporarily");
- header("Location: $ipns['store2']");
- ) urls []= $ipns['store2'];
- /* My Other And Better Store IPN Fingerprint */
- if (
- $_POST["receiver_email"] == $emails['store3']
- header("HTTP/1.1 302 Moved Temporarily");
- header("Location: $ipns['store3']");
- ) urls []= $ipns['store3'];
- /* ... */
- /* Broadcast */
- if ( !sizeof($urls)
- header( 'HTTP/1.1 200 OK', true, 200 );
- ) $urls = $ipns; /* No URLs have been matched */
- $urls = array_unique( $urls ); /* Unique, just in case */
- /* Log data (excluding IPNs from the list according to filter is possible */
- foreach ( $urls as $url ) log( $url );
- header( 'HTTP/1.1 200 OK', true, 200 );
- exit(); /* Thank you, bye */
- /* Log the data */
- function log( $url ) {
- /* Format POST data accordingly */
- $data = array();
- foreach ($_POST as $key => $value) $data []= urlencode($key).'='.urlencode($value);
- $data = implode('&', $data);
- /* Log the broadcast */
- file_put_contents('_logs/'.time().'.'.reverse_lookup( $url ).'-'.rand(1,100), $data);
- }
- function reverse_lookup( $url ) {
- global $ipns;
- foreach ( $ipns as $tag => $_url ) {
- if ( $url == $_url ) return $tag;
- }
- return 'unknown';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement