I have a PayPal IPN handler that has been working for over 5 years (with various updates over time). Suddenly yesterday I stopped receiving the normal '&' and '=' separated data string and started getting ~6 garbage non-ascii characters.
When I log the data coming directly into from PayPal, before any confirmation, parsing, handling, whatever, I normally get
[2016-07-13 04:46 UTC] Raw data handling_amount=0.00&discount=0.00&insurance_amount=0.00&payer_id=blah blah blah etc.
Now, I'm just getting this
[2016-07-13 04:37 UTC] Raw data xæÕ-
It's never the same set of characters, but always garbage (and only about 6 characters).
I've checked the encoding in my PayPal account and set it to UTF-8. Didn't help. I've used the PayPal IPN Simulator with the exact same code (address changed to sandbox) and it works perfectly. I've tried 3 separate IPNs resent from PayPal's IPN history, including 1 that didn't fail preiously. None of them work, all result in the same garbage data. I've tried handling the input from PayPal directly as $_POST and using file_get_contents('php://input'). There isn't any difference; everything works in the Simulator and it's just garbage from Live.
Here is my listener code. Its pretty much the same as the examples you see elsewhere online.
<?php
error_reporting(E_ALL ^ E_NOTICE);
define("LOG_FILE", "./ipn.log");
$raw_post_data = file_get_contents('php://input');
error_log(date('[Y-m-d H:i e] '). "Raw data " . $raw_post_data . PHP_EOL, 3, LOG_FILE);
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval)
{
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// Read the post from PayPal and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($myPost as $key => $value)
{
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
}
This just shows the data-receiving and parsing. Notice at line 7, the error_log call. This is where the above quotes come from. Normally, the data is fine (and with Sandbox it is fine). But suddenly, the log data for the Live site is garbage. The problem isn't connecting to PayPal or getting 'verified' or 'invalid' back because there isn't any data to verify or parse.
Has anyone experienced this before? It certainly seems like an encoding problem but I have set the encoding to UTF-8. And it's not like it's a partial encoding problem where some of the data is bad. The whole thing is bad. Thanks!
I contacted PayPal technical support but they never resolved this issue. I'm certain at this point it is an issue on their end as the only thing that fails is IPN resend. It was useful to have that, but I can survive without it.