<?php
// 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";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (0 == strcmp($res, "VERIFIED")) {
// 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
if("susbcr_signup" == $_POST['txn_type']){
$_id = $_POST['subscr_id'];
$websites= "websites";
$database = "k29803_1";
$link = mysql_connect("localhost", $username, $password) or die(mysql_error());
mysql_select_db($database, $link);
$query = "SELECT * FROM users WHERE username= 'drahoslava' AND password = 'drah0slava'";
$results = mysql_query($query, $link)or die(mysql_error());
if(1==mysql_num_rows($results)){
$add_credits = "UPDATE users SET hash = '$_id'
WHERE username= 'drahoslava' AND password = 'drah0slava'";
mysql_query($add_credits, $link) or die(mysql_error());
echo 'done';
}
mysql_free_result($results);
} elseif (0 == strcmp($res, "INVALID")) {
// log for manual investigation
}
}
}
fclose($fp);
}
?>
fclose needs to move, and mysql_free_result needs to be added. common mistake with mysql_free_result, the examples don't have it, but they should, code doesn't work without it.