How do I access a remote form in php?

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, PHP Tutorial  //  No Comments

I want to gather info from a user on a local php page , and use that info to query a form on another site

Here’s the code 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);

Leave a comment

Share This Post

RSS Wordpress News