I have been trying to figure out for the past 12 hours as to why this isn't working. I have found the most recent and updated code that everyone should now be using with the IPN system. In case you are unsure as to why the POST header is now HTTP/1.1 instead of HTTP/1.0, look here: https://www.x.com/content/bulletin-ipn-and-pdt-scripts-and-http-1-1
In any block of this script, a message should be placed in log.txt, but that doesn't even happen.
Any insight anyone can provide would be awesome:
<?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 (replaces old headers)
$header .="POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .="Content-Type: application/x-www-form-urlencoded\r\n";
$header .="Host: www.paypal.com\r\n";
$header .="Connection: close\r\n";
$fp = fsockopen ('ssl://paypal.com', 443, $errno, $errstr, 30);
//
//error connecting to paypal
if (!$fp) {
file_put_contents('log.txt', 'httperror');
}
//successful connection
if ($fp) {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$res = trim($res); //NEW & IMPORTANT
if (strcmp($res, "VERIFIED") == 0) {
if ($_POST["payment_status"] == "Completed") {
$link = mysqli_connect("localhost", "removedforsecurity", "removedforsecurity", "removedforsecurity");
if (!$link) {
printf("Can't connect to localhost. Error: %s\n", mysqli_connect_error());
exit();
}
$username = $_POST["custom"];
$date = date('Y-m-d');
/* update rows */
mysqli_query($link, "UPDATE users SET access='user' WHERE username='myusername'");
file_put_contents('log.txt', 'veri');
/* close connection */
mysqli_close($link);
}
}
if (strcmp ($res, "INVALID") == 0) {
file_put_contents('log.txt', 'failed');
}
}
fclose($fp);
}
?>