2013-07-04 2 views
1

IPN 데이터를 확인할 때 Paypal에서 "Invalid Host Header"오류가 발생합니다. 내 코드는 페이팔 샘플 코드 here과 거의 동일합니다. 아주 철저하게 샘플 코드에 비교를 통해Paypal IPN에서 잘못된 호스트 헤더 수신 오류

Thursday 4th of July 2013 01:20:38 PM: Starting IPN 
Thursday 4th of July 2013 01:20:38 PM: Sending: 
POST /cgi-bin/webscr HTTP/1.0 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 894 

cmd=_notify-validate&mc_handling1=1.67&address_state=CA&txn_id=1022805571&last_name=Smith&mc_currency=USD&payer_status=verified&address_status=confirmed&tax=2.02&invoice=abc1234&address_street=123%2C+any+street&payer_email=buyer%40paypalsandbox.com&mc_gross1=12.34&mc_shipping=3.02&first_name=John&business=seller%40paypalsandbox.com&verify_sign=A--8MSCLabuvN8L.-MHjxC9uypBtAgGbVpm-R.25XDqUbmKjsNIBMI1A&payer_id=TESTBUYERID01&payment_date=12%3A35%3A05+4+Jul+2013+PDT&address_country=United+States&payment_status=Completed&receiver_email=seller%40paypalsandbox.com&payment_type=instant&address_zip=95131&address_city=San+Jose&mc_shipping1=1.02&item_name1=something&mc_gross=15.34&item_number1=AK-1234&mc_fee=0.44&residence_country=US&address_country_code=US&notify_version=2.4&receiver_id=seller%40paypalsandbox.com&mc_handling=2.06&txn_type=cart&custom=xyz123&address_name=John+Smith&test_ipn=1 
Thursday 4th of July 2013 01:20:38 PM: Paypal response: HTTP/1.0 400 Bad Request 

Thursday 4th of July 2013 01:20:38 PM: Paypal response: Server: BigIP 

Thursday 4th of July 2013 01:20:38 PM: Paypal response: Connection: close 

Thursday 4th of July 2013 01:20:38 PM: Paypal response: Content-Length: 19 

Thursday 4th of July 2013 01:20:38 PM: Paypal response: 

Thursday 4th of July 2013 01:20:38 PM: Paypal response: Invalid Host header 

내가 갔어요, 그것은 거의 동일입니다 :

<?php 
eventlog('Starting IPN'); 
// 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 
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 

if(!$fp) $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); 

if (!$fp) { 
    // HTTP ERROR 
    eventlog('HTTP error sending return request from IPN:' . $errstr); 
} else { 
    eventlog('Sending:' . "\n" . $header . $req); 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) 
    { 
     $res = fgets ($fp, 1024); 
     eventlog('Paypal response: ' . $res); 
     if (strcmp ($res, "VERIFIED") == 0) { 

      // PAYMENT VALIDATED & VERIFIED! 
      if($_POST['payment_status'] === 'completed') 
      { 
       $custom = unserialize($_POST['custom']); 
       $email = $custom[1]; 
       while(isset($_POST['item_name' . $i])) 
       { 
        recordPayment($email, $_POST['item_name' . $i], $_POST['quantity' . $i], $_POST['mc_gross' . $i], 'Paypal'); 
        $i++; 
       } 
      }else 
      { 
       eventlog('Payment from ' . $email . ' not yet completed.'); 
      } 
     } else if (strcmp ($res, "INVALID") == 0) { 

      // PAYMENT INVALID & INVESTIGATE MANUALY! 
      eventlog('Invalid payment attempt: ' . $req); 
     } 
    } 
    fclose ($fp); 
} 
?> 

여기에 내 로그 파일에 얻고거야. 누구든지 내가 뭘 잘못하고 있는지 알아?

+0

당신이 HTTPS 요청을하는 대신에 당신을 위해 그것을 할 컬 사용하는 모든 작업을하고있는 어떤 이유 ? –

답변

4

이 헤더

$header .= "Host: www.sandbox.paypal.com\r\n"; 
누락
+0

고마워요, 고쳐 줘요! :) –

0
// post back to PayPal system to validate 
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
//$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; change with the line below 
$header .= "Content-Length: " . strlen($req) . "\r\n"; 
$header .= "Host: www.sandbox.paypal.com\r\n"; //and add this line 
그것은 나를 위해 일하고

)

관련 문제