问题
Few days ago suddenly it is stopped to receive IPN messages from paypal. I have written the code which are below
$url_parsed=parse_url('https://www.sandbox.paypal.com/cgi-bin/webscr');
$post_string = '';
foreach ($_POST as $field=>$value) {
$post_string .= $field.'='.urlencode(stripslashes($value)).'&';
}
$post_string.="cmd=_notify-validate";
$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
$myFile = "testpaypal.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $post_string;
fwrite($fh, $stringData);
fwrite($fh, "------------");
if(!$fp){
return false;
} else {
fputs($fp, "POST $url_parsed[path] HTTP/1.0\r\n");
fputs($fp, "Host: $url_parsed[host]\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($post_string)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $post_string . "\r\n\r\n");
while(!feof($fp))
{
$ipn_response .= fgets($fp, 1024);
}
fclose($fp);
if (eregi("VERIFIED",$ipn_response)) {
fwrite($fh, "VERIFIED");
return true;
} else {
fwrite($fh, "UNVERIFIED");
return false;
}
}
fclose($fh);
This code returns err_num to "0" as well as when i print $ipn_response after "fclose($fp);" line it prints "HTTP/1.0 302 Found Location: https://www.sandbox.paypal.com Server: BigIP Connection: close Content-Length: 0 "
but unable to get "VERIFIED" in $ipn_respnse.
i have tried all possible method such as change parse url with "ssl://sandbox.paypal.com" and all other solution suggested on web.
i have been stuck in this issue since last three days. So, please help me out.
thanks in advance.
回答1:
I also struggled with this problem once. It completely job me crazy!!! The problem was that Hetzner (where is hosting located) has blocked PayPal IP by some reason. In this case when you will look at the IPN histiry in the PayPal account you shoud see that IPN has stoped send notifications from some date.
回答2:
You should be connecting via SSL. Try changing this:
$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30);
To this:
$fp = fsockopen("tls://" . $url_parsed['host'],"443",$err_num,$err_str,30);
回答3:
try to change the parse_url(https://www.paypal.com/cgi-bin/webscr) to sandbox url(https://sandbox.paypal.com/cgi-bin/webscr).
Next, check your server has enabled with openssl for receiving response from HTTPS by using phpinfo() function.
回答4:
In a message from PayPal:
To improve our site’s performance, scalability and availability, we’re going to expand the number of IP addresses for www.paypal.com. We announced this in a bulletin on October 18, 2011. As part of this expansion, we’ll discontinue support for the HTTP 1.0 protocol on February 1, 2013...
Supposedly more information can be found at http://www.paypal.com/pdt and http://www.paypal.com/ipn
I noticed in your code here:
fputs($fp, "POST $url_parsed[path] HTTP/1.0\r\n");
you are still using HTTP 1.0
I do not know if this will resolve your issue, but hopefully it will help if you are still having a problem.
来源:https://stackoverflow.com/questions/14827497/unable-to-getting-response-from-paypal-ipn-sandbox