cURL Code Sample

cURL is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, FILE and LDAP. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication, file transfer resume, proxy tunneling, etc.

cURL is commonly needed for API communications between remote servers.


<?php
$site_url = 'http://example.com';
$ch = curl_init();$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, $site_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
ob_start();
curl_exec($ch);
curl_close($ch);
$file_contents = ob_get_contents();
ob_end_clean();

echo $file_contents;
?>

  • 51 Users Found This Useful
Was this answer helpful?

Related Articles

How to enable Php Register Globals?

To enable Php Register Globals: 1. Create php.ini files in the directory  that requires...

How to enable Session.Save_Path?

To enable Session.Save_Path: 1) Create folder "session" in public_html directory.2) Chmod 755...

Character Encoding i.e Chinese

The automatic method of choosing the character set is done by adding a META tag to the HTML of...