duanhanzi8328 2012-01-04 02:33
浏览 151
已采纳

使用fsockopen的PayPal IPN返回NULL

I'm trying to set up the PayPal IPN on my web application, I copied from PayPal's documentation on an example PHP snippet which is found here.

However, when I'm testing with the PayPal's sandbox, sending an IPN with the simulator which is found here.

Now, when PayPal sends the IPN, I log the actions and data of the IPN, when trying to open an connection with fsockopen, it is NULL when I do var_export on it.

I don't understand why it's not going any further with the code when the fsockopen connection is NULL.

I'm using Codeigniter for my application, and this is the part of the code that fails:

if($this->uri->segment(3) == 'ipn')
{
    $error_msg = '';

    $error_msg .= " initiated ";

    $req = 'cmd=_notify-validate';

    $error_msg .= " 

 req: " . var_export($req, true);

    foreach($this->input->post() as $key => $value) 
    {
        $value = urlencode(stripslashes($value));
        $req .= "&" . $key . "=" . $value;
    }

    $error_msg .= " 

 req: " . var_export($req, true);

    $header = '';
    $header .= "POST /cgi-bin/webscr HTTP/1.0
";
    $header .= "Content-Type: application/x-www-form-urlencoded
";
    $header .= "Content-Length: " . strlen($req) . "

";

    $error_msg .= " 

 headers: " . var_export($header, true);

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

    $error_msg .= " 

 fp: " . var_export($fp, true);

I use $error_msg to log the data, this is an example what is logged:

 initiated  

 req: 'cmd=_notify-validate' 

 req: 'cmd=_notify-validate&test_ipn=1&payment_type=echeck&payment_date=17%3A30%3A40+Jan+03%2C+2012+PST&payment_status=Completed&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer%40paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John+Smith&address_country=United+States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San+Jose&address_street=123%2C+any+street&business=seller%40paypalsandbox.com&receiver_email=seller%40paypalsandbox.com&receiver_id=TESTSELLERID1&residence_country=US&item_name=something&item_number=DX4WYSur44CQICgO2lC%2FB10NmdaiPNH3xPZXQNAlfrEqpse0xnime22zaNXDFgbRrOL4Xsz4emkhqFw4JhOSHzCtaHt9%2B0p9p8xW6R71PVbFXNyEVjkPeHNdQm32PJg&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&txn_type=web_accept&txn_id=4014130&notify_version=2.1&custom=xyz123&invoice=abc1234&charset=windows-1252&verify_sign=An5ns1Kso7MWUdW4ErQKJJJ4qi4-AN8d2a.xggmx9Dn4AgHpvPHJHTAp' 

 headers: 'POST /cgi-bin/webscr HTTP/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 969

' 

 fp: NULL

As you can see $fp is returning NULL on the last line of the logged data. Is there any idea why this is happening?

I can confirm I have OpenSSL enabled and installed on my server:

enter image description here

EDIT: Just tested fsockopen on port 80 to google.com, I still get NULL with no error number or message. So this problems occurs to every URL.

EDIT #2: Tested on my server by doing this:

fsockopen('ssl://www.paypal.com/cgi-bin/webscr', 443, $errno, $errstr, 30)

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to ssl://www.paypal.com/cgi-bin/webscr:443 (php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known)

  • 写回答

4条回答 默认 最新

  • dongyingla8668 2012-01-08 16:12
    关注

    Be careful of $config['csrf_protection'] = TRUE; this will block all external POSTS as they will not come with a CSRF token, I've had this with my paypal IPN before, I needed to enable a crude but effective way to get the callback (in config.php):

    if(stripos($_SERVER["REQUEST_URI"],'/paypal') === FALSE) {
      // disable CSRF for the /paypal 
        $config['csrf_protection'] = TRUE;
    } else {
        $config['csrf_protection'] = FALSE;
    }
    

    I'm guessing this could be an issue, you would get null as no data would be captured as CI reviews your $_POST/$_GET vars for security reasons.

    If I misunderstood your question and am way off track, just let me know via a comment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 求用matlab求解上述微分方程的程序代码
  • ¥15 请问各位,如何在Jetson nano主控板的Ubuntu系统中安装PyQt5
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致