Tip: Using cURL to submit post parameters

Here is cURL syntax to submit post parameters to a specific URL. $post_params array in the code below defines all the parameters to be submitted

<?php
	$request_url ='http://www.qualitycodes.com';
        $post_params['name'] = 'Stuart Carlos';
        $post_params['email'] = 'carlos887@gmail.com';
        $post_params['password'] = 'alpha22';
        $post_params['command'] = 'submit';
 
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $request_url);		// The url to which these parameters will be posted
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);		// We want to get the respone
        curl_setopt($ch, CURLOPT_POST, true);				// The submission type is post
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);	// The post array, containing all the parameters
        $result = curl_exec($ch);
		echo $result;
        curl_close($ch);
 ?>

 

More PHP tips