Skip to content

Instantly share code, notes, and snippets.

@willkriski
Created December 4, 2011 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willkriski/1430655 to your computer and use it in GitHub Desktop.
Save willkriski/1430655 to your computer and use it in GitHub Desktop.
Submit to Form using cURL
<?php
//create array of data to be posted
$post_data['Z_ACTION'] = '';
$post_data['Z_START'] = '';
$post_data['P_TAX_AUTH'] = '604';
$post_data['P_STREET_NUMBER'] = '';
$post_data['P_STREET_NAME'] = 'CARRIAGE CRT';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
curl_init('https://www.planet.snb.ca/ANONDB/anon002$.querylist');
//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);
curl_setopt($curl_connection, CURLOPT_POST, true);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
echo $result;
//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);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment