Post Form Data with CURL and get Results

Today, I am doing another domain name related project(on of my specialties). I need a fresh PHP function to get a domain name’s whois data from. It’s time to get dirty with CURL because all my PHP whois functions are failing lately after about 500 queries or less, so let’s do this!


The first thing I needed was a decent CURL function to post to a URL and get results. Here is what I found:

function curlPost($url, $data){
// check for URL and data:
        return ‘Error: missing URL’;
        return ‘Error: missing Data’;

//get the data for the POST and put in URL:
$fields_string = ”;
foreach($data as $key=>$value) { $fields_string .= $key.’=’.$value.’&’; }
$fields_string = rtrim($fields_string,’&’);

//open connection
$ch = curl_init();

//Set the URL, no. of POST vars and POST data:

//timeout after 10 secs(change as needed):
//Set to return data instead of printing:
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
//pass user agent:
curl_setopt($ch,  CURLOPT_USERAGENT , “Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)”);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

//execute post:
$result = curl_exec($ch);

//close connection:
return $result;
}//end curlPost function.

echo “<h3>Whois test</h3>”;
$data = array(‘d43b’ => ‘’);
echo curlPost(‘’, $data);


Okay, I know, unfair, I took out the target domain, but find your own lol. I don’t want everyone exploiting the poor server. But I was still limited with this technique because the server I queried had a maximum number of queries allowed, so I still need to find out how to overcome this.

One Reply to “Post Form Data with CURL and get Results”

  1. hello id like to use curl to post form data to another website and get results but i can’t understand Curl library could u pl explain ….

Leave a Reply

Your email address will not be published. Required fields are marked *