############################################################################################################################ ################## PayPal IPN verification - by Carol Braileanu of CyberTech SRL - cartman@b.astral.ro ################## ############################################################################################################################ // build the POST string adding the cmd=_notify-validate value $req = "cmd=_notify_validate"; foreach($_POST as $key=>$value) { $value = urlencode(stripslashes($value)); $req .= "&" . $key . "=" . $value; } // construct the form to post $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"; // open connection to server $fp = fsockopen("www.paypal.com", 80); $item_number = $_POST["item_number"]; $payment_status = $_POST["payment_status"]; $txn_id = $_POST["txn_id"]; if(!$fp) { echo "cant contact IPN server"; } else { fputs($fp, $header . $req); while(!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, "VERIFIED")==0) { echo "successful"; } else if (strcmp($res, "VERIFIED")==0) { echo "invalid"; } } fclose ($fp); }