Oct.28

Apr.22

How to Submit a form Using cURL (POST)


// URL of Form
$url = "http://www.url.com/to/form.php";

//create the final string to be posted
$post_string = "submit=values&text=sometext";

//create cURL connection
$curl_connection =
curl_init($url);

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' .
// curl_error($curl_connection);

//close the connection
curl_close($curl_connection);

Web Programming,Web SEO