Breaking News
Home / Web / PHP / PHP Snippets / How to get contents of a URL using Curl in PHP?

How to get contents of a URL using Curl in PHP?

Snippet

  1. // get contents via curl
  2. function curl_get($url){
  3.    $browser_agent = "Firefox";
  4.    $ch=curl_init();
  5.    curl_setopt($ch,CURLOPT_URL,$url);
  6.    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  7.    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  8.    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);              
  9.    curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
  10.    curl_setopt($ch,CURLOPT_USERAGENT, $browser_agent);
  11.    $result=curl_exec($ch);
  12.    curl_close($ch);
  13.  return$result;
  14. }
[pb_builder]

Check Also

How to list files in a directory in PHP?

<?php if ($handle = opendir(‘/path/to/directory’)) {     echo "Directory handle: $handlen";     echo …

Leave a Reply