kipper Posted November 19, 2009 Share Posted November 19, 2009 It's fairly straightforward to submit to paypal with a GET. Something like: $data = http_build_query($fields); $final_url = $url . "?" . $data; header( 'Location: $final_url'); Takes you to paypal where you can put in credit card info and pay. BTW $url = https://www.sandbox.paypal.com/cgi-bin/webscr and $fields is an assoc array with customer contact and purchase information. cmd needs to be _cart. The problem is GET has a size limit that's not huge. It would be better to use POST. It has to be possible since forms do it all the time. Does anyone know how to do this programmatically? In other words, how do you set up the header info as a post and zip someone off to paypal? I have found a few things on the net but nothing actually works. Any help would be REAL help. Quote Link to comment https://forums.phpfreaks.com/topic/182096-how-to-submit-post-info-to-paypal-with-header/ Share on other sites More sharing options...
premiso Posted November 19, 2009 Share Posted November 19, 2009 You may want to look into curl as I believe it has the functionality you want. Quote Link to comment https://forums.phpfreaks.com/topic/182096-how-to-submit-post-info-to-paypal-with-header/#findComment-960633 Share on other sites More sharing options...
kipper Posted November 19, 2009 Author Share Posted November 19, 2009 That's a good idea but there are problems. The default user agent from curl tells paypal the request came from a script. I suppose I could pass the visitors user agent. But that's not all. Here is some code I adapted (stole) from the php.net site: $url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; $data = http_build_query($fields); $alternate_opts = array( 'http'=>array( 'method'=>"POST", 'header'=>"Content-type: application/x-www-form-urlencoded\r\n" . "Content-length: " . strlen($data), 'content'=>$data ) ); $alternate = stream_context_create($alternate_opts); readfile($url, false, $alternate); This got me to the login to the sand box page. Since I was already logged in I'm guessing paypal is not seeing the login cookie. Assuming the code I swiped is bulletproof and I didn't mess something up. Quote Link to comment https://forums.phpfreaks.com/topic/182096-how-to-submit-post-info-to-paypal-with-header/#findComment-961409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.