Skip to content Skip to sidebar Skip to footer
Reading Time: < 1 minute

How to submit with data to another web site’s form and get its results using php?You can remote submit a form using curl functions.Then can get it’s results.This is named as scraping also.Let’s see how to remote submit a form and get it’s result using php curl.

This is the web site form.You must already have a prior knowledge of that form.You can view it in the page source.

ok.So now we have knowledge of the form.But you don’t need this code.Only know about the input fields.
Now we’ll see how to submit this using php curl functions.

// THIS ARRAY CONTAINS THE INPUT FIELDS DATA
   $data = array(
                 'username' => 'usersname567890',
                 'password' => '12345pswd'
   );
// START THE CURL PROCESS
$ch = curl_init(); // initialize
curl_setopt($ch, CURLOPT_URL, 'https://webexplorar.com'); // form location url
curl_setopt($ch, CURLOPT_POST, 1); // form method
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // input fileds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // get form result details
$html = curl_exec($ch); // execute the curl process
// DISPLAY FORM SUBMITTED RESULT
 print_r($_POST);

That is only you have to do get for remote submit a form and get it’s results using curl in php.
If you want to get it’s specific data you can use php DOM object.

$dom = new DOMDocument(); // create DOM object
@$dom->loadHTML($html);// load it's all html contents
$nodes = $dom->getElementsByTagName('*'); // get all html contents as tags.
print_r($nodes); / this is an array
foreach($nodes as $node){
	if($node->nodeName == 'p'){
           $node->nodeValue;
        }
}

Easy now to get specific details.