Php Curl

How To Send POST data with cURL.

You may want to pass data to another url using data from the database,in this way a user does not need to enter the data in the form,you can use GET to pass it however the data will be availlable on the url and therefore a user may temper with it or collect it and use it for other malicious intentions.

We achieve this using cURL which transfers data using different protocols,here is a snippet on how to use cURL.


// Get cURL resource
$curl = curl_init();
// Set some options
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'http://localhost/curlpost/receive.php',
CURLOPT_USERAGENT => 'Code Snippet from https://uxtcloud.com',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => [
domain => 'uxtcloud.com',
email => '[email protected]',
phone => '254797669121',
purpose => 'web hosting'
]
]);
// Send the request and test for error
if (!curl_exec($curl)) {
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
// Close request to clear up some resources
curl_close($curl);

Copy the code above in to your text editor and change the parameters accordingly.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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