Posted By

rabc on 08/07/10


Tagged

curl url php open


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

melihbuyuk


Open URL


 / Published in: PHP
 

Little function to open an URL using cURL. @params $url - the URL to open @params $cookie [optional] - the path where cookie is (see my other function openCookie()) @return string with the URL contents

  1. function openURL($url,$cookie='') {
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL, $url);
  4. if($cookie!='') {
  5. // set the cookie file
  6. curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
  7. }
  8. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  9. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  11. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  12. // Acessar a URL e retornar a saĆ­da
  13. $output = curl_exec($ch);
  14. // liberar
  15. curl_close($ch);
  16.  
  17. return $output;
  18. }

Report this snippet  

You need to login to post a comment.