Advertisement
cgrunwald

Untitled

Sep 5th, 2010
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.32 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Calls request functions sequentially.
  5.  * @return  void
  6.  */
  7. function MakeRequests()
  8. {
  9.     $reqResponse = execReq_www_google_com();
  10.     if ($reqResponse['success'])
  11.     {
  12.         /* Successful web request. You can now use $reqResponse['response'] to get the response object. */
  13.         $response = $reqResponse['response'];
  14.  
  15.     }
  16.     else
  17.     {
  18.         /* Failure, cannot use $reqResponse['response'] */
  19.     }
  20. }
  21.  
  22.  
  23.         /**
  24.          * Tries to request the URL: http://www.google.com/
  25.          * @return  array
  26.          */
  27. function execReq_www_google_com()
  28. {
  29.             // Null out the response beforehand..
  30.             $response = NULL;
  31.  
  32.             // Create request to URL.
  33.             $request = curl_init();
  34.     curl_setopt ($request, CURLOPT_URL,"http://www.google.com/");
  35.     curl_setopt ($request, CURLOPT_IGNORE_CONTENT_LENGTH, 1);
  36.  
  37.             // Set request headers.
  38.             curl_setopt ($request, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8");
  39.             curl_setopt ($request, CURLOPT_ENCODING, "gzip,deflate");
  40.             curl_setopt ($request, CURLOPT_COOKIE, "PREF=ID=095864ae848ee5d3:U=338ba9bb0fe625b3:LD=en:NR=100:CR=2:TM=1283685796:LM=1283685796:GM=1:IG=3:S=D3-ZdATPqAvDPjcz; NID=38=1GeLw2zOceGNIzkneGS8biUaVyUiqzQM8tC-407Wy3GmGH_p_IaLgyxV0Rw0htvD8r-Qs6CHJ3LtrvlJjT-frFyZiiAJU_Zx5ZBdDW-nDQyvR78qX3ZXLI9woRqNPbUb; rememberme=true; SID=DQAAAJUAAACVkDK_0mGPIRbFONToK5IieAA_IfWamNG30p6_Q7FvO8h6HmiVu0Ns5O1isWvVmr7i7BUT7AURN2W_qwsLIPtoWgPrc1Ke4grNdIQ4t5ZWqDY804PT4L3RG2k8dG6L9mlko82aDTyhaIbLtpKEJIEAQ8J3TLm1qyiuJERFEjqSd8jyUC2yfTtSMmIjWY9QK2lQEKtsDEoUJn1zI5VERuHx; HSID=AaUcLGhxqvs_nq4eA; TZ=420");
  41.             curl_setopt($request, CURLOPT_HTTPHEADER, array(
  42.                 "Host: www.google.com",
  43.                 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json",
  44.                 "Accept-Language: en-us,en;q=0.5",
  45.                 "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
  46.                 "Keep-Alive: 115",
  47.                 "Connection: keep-alive",
  48.             ));
  49.  
  50.             // Get response to request.
  51.             $response = curl_exec($request);
  52.     curl_close($request);
  53.  
  54.     /* Error Checking */
  55.     if ($error = curl_error($request)) {
  56.         print "Error: $error<br />\n";
  57.         $response = NULL;
  58.         return array('success' => false, 'response' => $response);
  59.     } elseif (empty($response)) {
  60.         print "Error: Empty response.<br />\n";
  61.         $response = NULL;
  62.         return array('success' => false, 'response' => $response);
  63.     }
  64.  
  65.     return array('success' => true, 'response' => $response);
  66. }
  67.  
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement