2
Dec

CURL POST Variable Submission

A simple example on how to submit POST variables to a page using the cURL library and handle the server response by accepting temporary cookies.

<?php
// Set the URL that will handle the POST variables
$url = 'http://www.site.com';

// Set username and password values below...
$username = 'username';
$password = 'password';

// Initialize cURL
$ch = curl_init();

// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);

// Accept cookies
curl_setopt($ch,CURLOPT_COOKIEFILE,1);

// Submit our POST values (EG: username and password)
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "username=$username&password=$password");

// Execute...
$output = curl_exec($ch);

// Display the result
echo $output;
?>

Permalink | Comments (0) | Post RSS