I want to gather info from a user on a local php page (that I control), and use that info to query a form on another site (that I don't control) - how do I do that?
if you are using linux i suggest curl but here is a generic class i use http://willwharton.com/http.phps that works on linux and windows as it can use both curl and fsockopen()
$http = new Http();
$http->setMethod('POST');
$http->addParam('aaaa' , 'bbb');
$http->addParam('ccccc' , 'ddddd');
$http->execute('http://www.namecheap.com/myaccount');
$raw = $http->result;
Here's the code I ended up using, using curl:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $formurl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user_id=$id&password=$pw");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // required to work with https:// sites.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // curl_exec() returns page, instead of printing it.
$page = curl_exec($ch);
if ($page == false) {
$curlerror = curl_error($ch);
print "<br>Errors: $curlerror<br>\n";
}
else {
print "<br>curl call succeeded<br>\n";
print $page;
}
curl_close($ch);
What version of PHP are you using? I will assume 5.x.
PHP includes easy to use classes for HTTP operations. The documentation can be found here: http://us3.php.net/manual/en/ref.http.php
There are several ways to approach this: one is capturing the input on your local form and POST-ing the data to the remote form using http_post_fields()
.
Keep in mind, when posting data from one server to another, that foreign server may ignore your request. So be sure to test against that, and if you are unsuccessful, contact the person who has access to configure the server to accept requests from your local server.