PHP   19

getUrlContent

Guest on 27th April 2022 05:37:59 PM

  1. <?php
  2. function getUrlContent($url){
  3. $ch = curl_init();
  4. curl_setopt($ch, CURLOPT_URL, $url);
  5. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  8. curl_setopt($ch, CURLOPT_REFERER, 'http://www.bbc.co.uk/1');
  9. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  10. $data = curl_exec($ch);
  11. $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  12. echo $data;
  13. return ($httpcode>=200 && $httpcode<300) ? $data : false;
  14. //echo $data;
  15. }
  16. $cnn = getUrlContent('/week4/serveitup.php');
  17.  
  18. ?>

Raw Paste


Login or Register to edit or fork this paste. It's free.