Posted By

akshay_raje on 03/27/11


Tagged

curl http filegetcontents


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

zietbukuel


Basic cURL wrapper function for PHP


 / Published in: PHP
 

  1. /**
  2.  * Basic cURL wrapper function for PHP
  3.  * @link http://snipplr.com/view/51161/basic-curl-wrapper-function-for-php/
  4.  * @param string $url URL to fetch
  5.  * @param array $curlopt Array of options for curl_setopt_array
  6.  * @return string
  7.  */
  8. function file_get_contents_curl($url, $curlopt = array()){
  9. $ch = curl_init();
  10. $default_curlopt = array(
  11. CURLOPT_TIMEOUT => 2,
  12. CURLOPT_RETURNTRANSFER => 1,
  13. CURLOPT_FOLLOWLOCATION => 1,
  14. CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 AlexaToolbar/alxf-1.54 Firefox/3.6.13 GTB7.1"
  15. );
  16. $curlopt = array(CURLOPT_URL => $url) + $curlopt + $default_curlopt;
  17. curl_setopt_array($ch, $curlopt);
  18. $response = curl_exec($ch);
  19. if($response === false)
  20. trigger_error(curl_error($ch));
  21. curl_close($ch);
  22. return $response;
  23. }

Report this snippet  

You need to login to post a comment.