I was trying to follow the tutorial on paypal's developer site on setting up a basic IPN listener, and it looks nearly syntax for syntax like on their example. In fact when I started receiving the errors I've been receiving, I thought I would create a new ipn listener and use just the code they have in their example to see if it was my code or not and received the same errors.
Warning: fgets(): supplied argument is not a valid stream resource in \supergate\ipn.php on line 42
Warning: feof(): supplied argument is not a valid stream resource in \supergate\ipn.php on line 39
the errors on those line numbers are for these pieces of code at those lines:
while (!feof($fp)) //line 39
{
$res = fgets($fp, 1024); //line 42
here is the rest of the entire code
<?php
//Empty Header HTTP 200 OK reponse to ack receipt of the notification
header('HTTP/1.1 200 OK');
///////////////////////////////////////////////////////
//assign payment notification values to local variables
$item_name =$_POST['item_name'];
$item_number =$_POST['item_number'];
$payment_status =$_POST['payment_status'];
$payment_ammount =$_POST['mc_gross'];
$payment_currency =$_POST['mc_currency'];
$txn_id =$_POST['txn_id'];
$receiver_email =$_POST['receiver_email'];
$payer_email =$_POST['payer_email'];
///////////////////////////////////////////////////////
//build the required ack message of notification just received
$req = 'cmd=_notify-validate'; //add 'cmd=_notify-validate' to beginning of acknowledgement
foreach ($_POST as $key => $value) { //loop through the notification nv pairs
$value = urlencode(stripcslashes($value)); //encode these values
$req .= "&$key=$value"; //add the nv pairs to the acknowledgement
}
//set up the acknowledgement request headers
$header = "POST /cgi-bin/webscr HTTP/1.1
"; //HTTP POST REQUEST
$header .="Content-Type: application/x-www-form-urlencoded
";
$header .="Content-Length: " .strlen($req) . "
";
// Open a socket for the acknowledgement request
$fp = fsockopen('ssl://sandbox.paypal.com', 443, $errno, $errstr, 30);
//send the http post request back to paypal for validation
fputs($fp, $header . $req);
while (!feof($fp))
{
$res = fgets($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0)
{
//WRITE TO EMAIL
*/
}
//--------------------------------------------------------------------------------------------------------------------
else if (strcmp($res,"INVALID") == 0)
{
//write to email
}
fclose($fp); //close the file
?>
Okay now the new warning I get is this:
Warning: fgets() [function.fgets]: SSL: An existing connection was forcibly closed by the remote host.