Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 2.44 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. PHP cURL connection HTTPs [closed]
  2. /**
  3.  * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
  4.  * array containing the HTTP server response header fields and content.
  5.  */
  6. function get_web_page( $url )
  7. {
  8.     $options = array(
  9.         CURLOPT_RETURNTRANSFER => true,     // return web page
  10.         CURLOPT_HEADER         => false,    // don't return headers
  11.         CURLOPT_FOLLOWLOCATION => true,     // follow redirects
  12.         CURLOPT_ENCODING       => "",       // handle all encodings
  13.         CURLOPT_USERAGENT      => "spider", // who am i
  14.         CURLOPT_AUTOREFERER    => true,     // set referer on redirect
  15.         CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
  16.         CURLOPT_TIMEOUT        => 120,      // timeout on response
  17.         CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
  18.     );
  19.  
  20.     $ch      = curl_init( $url );
  21.     curl_setopt_array( $ch, $options );
  22.     $content = curl_exec( $ch );
  23.     $err     = curl_errno( $ch );
  24.     $errmsg  = curl_error( $ch );
  25.     $header  = curl_getinfo( $ch );
  26.     curl_close( $ch );
  27.  
  28.     $header['errno']   = $err;
  29.     $header['errmsg']  = $errmsg;
  30.     $header['content'] = $content;
  31.     return $header;
  32. }
  33.        
  34. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false)
  35.        
  36. /**
  37.  * Get a web file (HTML, XHTML, XML, image, etc.) from a URL.  Return an
  38.  * array containing the HTTP server response header fields and content.
  39.  */
  40. function get_web_page( $url )
  41. {
  42.     $options = array(
  43.         CURLOPT_RETURNTRANSFER => true,     // return web page
  44.         CURLOPT_HEADER         => false,    // don't return headers
  45.         CURLOPT_FOLLOWLOCATION => true,     // follow redirects
  46.         CURLOPT_ENCODING       => "",       // handle all encodings
  47.         CURLOPT_USERAGENT      => "spider", // who am i
  48.         CURLOPT_AUTOREFERER    => true,     // set referer on redirect
  49.         CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
  50.         CURLOPT_TIMEOUT        => 120,      // timeout on response
  51.         CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
  52.         CURLOPT_SSL_VERIFYPEER => false     // Disabled SSL Cert checks
  53.     );
  54.  
  55.     $ch      = curl_init( $url );
  56.     curl_setopt_array( $ch, $options );
  57.     $content = curl_exec( $ch );
  58.     $err     = curl_errno( $ch );
  59.     $errmsg  = curl_error( $ch );
  60.     $header  = curl_getinfo( $ch );
  61.     curl_close( $ch );
  62.  
  63.     $header['errno']   = $err;
  64.     $header['errmsg']  = $errmsg;
  65.     $header['content'] = $content;
  66.     return $header;
  67. }