I have a form created with 2 fields and a submit button. But i want to do the same thing using Curl.
i tried it by using following code:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
$result = curl_exec($ch);
curl_close($ch);
$fields
included the two fields.
but the required output never came.
is there a way to do this successfully?
Also, be sure to set CURLOPT_FOLLOWLOCATION to TRUE if the url supplied redirects at all using a Location: header....
To get output set CURLOPT_RETURNTRANSFER in TRUE:
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
First, $fields
must be like this:
$fields = "user=".$_POST['user']"&password=".$_POST['password'];
In my case, my fields called user and password. Second, in order to see returned result, you have to set CURLOPT_RETURNTRANSFER to true:
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);