Curl code for file inclusion

by Sapphire (October 1, 2008)

LinkWorth’s instructions for running rotating links on your site involve plain vanilla file inclusion, which my host has turned off because it uses one of the most commonly abused php protocols (fopen). If I sound like I know what I’m talking about, give me an Oscar because I didn’t 15 minutes ago!

I put their code on my pages and it just generated errors. I remembered that this had happened a while back, and another host had provided me with a snippet of “curl code” which runs the included file without requiring the host to open the whole server up to hackers. I decided I could DIY this one, and went search for curl code. It was so easy to implement:

<?php
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, ‘http://www.example.com‘);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);

// display file
echo $file_contents;
?>

The only thing you need to change here is the bolded bit, “http://www.example.com.” That should be the URL of the file you’re including. LinkWorth provided this in their simple code, so I popped it in and that was that.

Your Ad Here


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>