I’m trying to have the PAYPAL IPN work with 2 different sites, I can’t get the php script to know which database to work with. Here’s my script.
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
// If testing on Sandbox use:
//$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// assign posted variables to local variables
$custom = $_POST['item_name'];
//Config file for 1st database
if($custom=="1"){
require_once("../config.php");
//Script to execute
}
//Config file for 2nd database (different site)
if($custom=="2"){
require_once("../config.php");
//Script to execute
}
Your code is making a lot of assumptions and isn’t very defensive. It’s assuming the form was posted, that it was successfully populated, that
$_POST['item_name']will contain only the strings ‘1’ or ‘2’ and that your script is running in a path which is one folder deep to a directory containing config.php…and that regardless of the condition, the same config.php will be loaded and miraculously know what it needs to do.What would make more sense is something like this:
Then you could have your configs setup like so: