我一直在使用PHP試驗curl訪問PayPal支付授權網站。PayPal cookies是否鏈接到IP地址?
例如
... $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $res = curl_exec ($ch); preg_match_all('/Set-Cookie: .*/', $res, $cookieMatches); foreach ($cookieMatches[0] as $cookieMatch) header($cookieMatch); preg_match('/Location: .*/', $res, $locMatches); header($locMatches[0]); header('Vary: Accept-Encoding'); header('Strict-Transport-Security: max-age=500'); header('Transfer-Encoding: chunked'); header('Content-Type: text/html');
的原則就是簡單地反映原始重定向(我相信有更簡單的方法來做到這一點)。但是,PayPal的迴應似乎表明某種cookie錯誤。
我的預感是cookie已經以某種方式與原始機器相連接。任何人都可以證實這一點,或者我只是錯過了明顯的東西!
謝謝你的建議 - 也應該設置CURLOPT_COOKIEFILE。我最初嘗試了這種方法,但PayPal賬單細節或登錄提交表單然後失敗。與直接的HTML表單提交相比,瀏覽器中似乎缺少了一些cookie。一個HTTP嗅探器證實了這一點 - 這就是爲什麼我嘗試上述。 – mayfly 2009-12-03 18:11:46