PHP Using cURL in PHP POST Requests


If you want to mimic HTML form POST action, you can use cURL.

// POST data in array
$post = [
    'a' => 'apple',
    'b' => 'banana'

// Create a new cURL resource with URL to POST
$ch = curl_init('');

// We set parameter CURLOPT_RETURNTRANSFER to read output
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Let's pass POST data
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

// We execute our request, and get output in a $response variable
$response = curl_exec($ch);

// Close the connection