База данных является большой как часть Вашей программы. Если quering данные является частью Вашей бизнес-логики. XML является лучшим как формат файла, особенно если Вы формат данных:
1, Hierarchal
2, Вероятно, для изменения в будущем способами, которыми Вы не можете предположить
3 данные собираются жить дольше, чем программа
Это должно работать:
$tid = $_GET['tx'];
$auth_token = "zzzzzzzzzzzzzzzzzzzz";
$paypal_url = "www.sandbox.paypal.com";
$url = "https://" . $paypal_url . "/cgi-bin/webscr";
$post_vars = "cmd=_notify-synch&tx=" . $tid . "&at=" . $auth_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_vars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'cURL/PHP');
$fetched = curl_exec($ch);
$lines = explode("\n", $fetched);
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0) {
for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$itemname = $keyarray['num_cart_items'];
$amount = $keyarray['mc_gross'];
echo ("<h2>Thank you for your purchase!</h2>");
}
else if (strcmp ($lines[0], "FAIL") == 0) {
echo ("<h2>Sorry, something went wrong</h2>");
// log for manual investigation
}
Также поиск $ _GET ['tx'] перестает работать примерно через 5 минут
Maybe not exactly what you want as an answer, but I just keep recommending this script if you want to use PayPal from PHP:
http://www.micahcarrick.com/04-19-2005/php-paypal-ipn-integration-class.html
Very clean script, which makes it easy to understand the parts of a transaction and edit things.
It also comes with examples provided on how to use the script with PayPal's sandbox. If I remember correctly, you just have to change one variable (and you obviously need an account for the sandbox).