PHP Code For Including Remote Content

If you ever need to include content from another domain in your web page, this code will come in handy  because it offers two options. First, the script checks to see if curl is available and then falls back on file_get_contents. Between the two, you should be able to get the content.

$page = ‘http://www.domain.com’;

if (function_exists(’curl_init’)) {
$ch = curl_init($page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, ”);
$code=curl_exec($ch);
curl_close($ch);
} else {
$code = file_get_contents($page);
}

echo $code;

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>