Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlexander Kapriniotis
25,897 PointsSubmit a Form in a page and the redirect to external url and use my post data in that domain
I want to do the same thing i have in my header, i want to simulate a payment gateway that takes some data from a form and then redirects to the payment page which is in an external url
1 Answer
Curtis Schrum
10,174 PointsWhen HTTP performs a redirect all POST data is lost because the browser performs a GET request.
You could convert the data to GET and send it along in the url however, this is a bad practice. It would potentially reveal secure information in the address bar with the URL.
A better option would be to use cURL to do a post to the URL via a class.
<?php
Class CurlExample
{
protected function transmitData($data, $url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_exec($curl);
}
}
That is one option. You could also use Buzz\Browser a PHP extension you can use instead of cURL.
However, the best idea is to use an API. Most payment gateways have an API you can hook into in order to send them the data they are expecting.
I hope this was helpful.