PHP: programmatically submit a form and get the contents of the summary page?

How would I programmatically submit a form using PHP (suppose using curl?) And get the file markup on the resulting page?

+3
source share
1 answer

See here for more details:

http://www.html-form-guide.com/php-form/php-form-submit.html

eg:

<?php
   $url = 'http://localhost/curl/1.php';
   $params = "keyword=123&zxczxc=333"; //you must know what you want to post
   $user_agent = "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)";
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_POST,1);
   curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
   curl_setopt($ch, CURLOPT_URL,$url);
   curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

   $result=curl_exec ($ch);
   curl_close ($ch);

   echo "Results: <br>".$result;
?>

1.php content:

<?
print_r($_POST);
?>

Questions Related to SO:

https://stackoverflow.com/search?q=php+form+curl

Publish a text area using cURL

Using PHP and curl to publish html form containing file

php cURL, fill out the remote form

Other articles:

http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html

http://davidwalsh.name/execute-http-post-php-curl

http://curl.haxx.se/mail/curlphp-2004-04/0013.html

http://phpsense.com/php/submitting-forms-using-php-curl.html

http://www.maheshchari.com/submit-a-form-to-remote-server-with-php-curl/

+7

Source: https://habr.com/ru/post/1778286/


All Articles