How to automatically submit a (POST) form from remote server? How to automatically submit a (POST) form from remote server? curl curl

How to automatically submit a (POST) form from remote server?


You can't fill the form with php since php is a server-side language. You could fill in the form with javascript. There are some frameworks to do that (phantomjs, casperjs).

You can try to post the form data directly using curl in PHP.

<?php$data = array(    'submit_form' => 1,    'field_name' => 'your value here',);$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://www.example.com/post-url");curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $data);$output = curl_exec($ch);$info = curl_getinfo($ch);curl_close($ch);

You can find the url by looking in the console of your browser:

form post

Your request might be blocked because it's coming from another server but you can give it a try. If you want to 'mimic' a normal visitor you can start with setting the user agent string, maybe modify the HTTP_REFERER as well.

curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36');curl_setopt($ch, CURLOPT_REFERER, 'http://www.example.com/the-url-of-the-form');


$(document).ready(function(){    $('#form1').submit(ajax);})function ajax(){        $.ajax({            url : 'inserir.php',            type : 'POST',            data : $('form').serialize(),            success: function(data){                $('#resultado').html(data);            }        });        return false;}...window.onload=function(){    setInterval(ajax, 5000);}