I’m running PayPal’s IPN simulator. I am using the following code, which I got from a tutorial, to create a listener.:
[code=php]
<?php
header(“HTTP/1.1 200 OK”);
$resp = ‘cmd=_notify-validate’;
foreach($_POST as $parm => $var)
{
$var = urlencode(stripslashes($var));
$resp .= “&$parm=$var”;
}
$payment_status = $_POST[“payment_status”];
$httpshead = “POST /cgi-bin/webscr HTTP/1.0rn”;
$httpshead .= “Content-Type: application/x-www-form-urlencodedrn”;
$httpshead .= “Content-Length: ” . strlen($resp) . “rnrn”;
$errno = ”;
$errstr = ”;
$fh = fsockopen(‘ssl://www.paypal.com’, 443, $errno, $errstr, 30);
fputs($fh, $httpshead . $resp);
while(!feof($fh))
{
$readresp = fgets($fh, 1024);
if(strcmp($readresp, “VERIFIED”) == 0)
{
file_put_contents(“response.txt”, “The payment status is: ” . $payment_status);
}
else if(strcmp($readresp, “INVALID”) == 0)
{
file_put_contents(“response.txt”, $readresp);
}
}
fclose($fh);
?>
This listener is designed to retrieve the POST message sent to it by the PayPal server, and return the exact same message back to PayPal’s server (preceded by ‘cmd=_notify-validate’). However, when I run the simulator, my response keeps coming up as invalid because the message I send back is not the EXACT same as the message sent from PayPal. I can’t see what I’m doing wrong, but I have a feeling it has to do with the encoding of $