CURL and access a site remotely

if you want to access a file from another server, you can use,

file_get_contents, file, fopen etc

function,
but they are disabled on certain servers. so we should always
use curl to remotely access a file, or to remotely login a site,
CURL work as a hidden browser.

Here is a sample code to get content from google

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, “http://www.google.com/search?hl=en&q=xml&btnG=Google+Search”);
$content = curl_exec ( $ch );
curl_close($ch);
echo $content;

this is a simple example, you can use CURL for more complex works. I’ll write here
another CURL advanced example soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s