Posted By

browncardigan on 02/08/10


Tagged

curl


Versions (?)

curlContents


 / Published in: PHP
 

URL: http://bettesmidler.com

  1. function curlContents($url=false, $data=array()) {
  2. $contents = '';
  3. if ($url) {
  4. $ch = curl_init();
  5. $timeout = 0; // set to zero for no timeout
  6. curl_setopt($ch, CURLOPT_URL, $url);
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  9. curl_setopt($ch, CURLOPT_COOKIESESSION, true);
  10. if (count($data) > 0) {
  11. curl_setopt($ch, CURLOPT_POST, true);
  12. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  13. }
  14. $contents = curl_exec($ch);
  15. curl_close($ch);
  16. }
  17. return $contents;
  18. }

Report this snippet  

You need to login to post a comment.