Make a request from one server to another

From Knowledge Kitchen
Jump to navigation Jump to search

cURL is a library that allows you to fetch URLs, like a browser does. but from your own server-side code.

Basic PHP example


// OK cool - then let's create a new cURL resource handle
$ch = curl_init();

// Set URL to download
curl_setopt($ch, CURLOPT_URL, "");

// User Agent
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Android; Mobile; rv:13.0) Gecko/13.0 Firefox/13.0");

// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);

// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

// Download the given URL, and store the returned data in a variable
$output = curl_exec($ch);

// Close the cURL resource, and free system resources

//send the content to the browser
echo $output;


What links here