title: CURL page to Lynda.com
body: <p>I am a member of Lynda.com, I want to fetch a HTML page from their site and save it onto my disk, the problem is whenever I try to fetch a page via CURL, I get the non-member page (it asks me to sign up), I cant understand why I cant get the members page :(</p>
  
  <p>My code:</p>
  
  <pre><code>get_remote_file_to_cache();
  
  function get_remote_file_to_cache()
  {
  
      $the_site = "http://www.lynda.com/AIR-3-0-tutorials/Flex-4-6-and-Mobile-Apps-New-Features/90366-2.html";
  
      $curl = curl_init();
      $fp = fopen("cache/temp_file.html", "w");
      curl_setopt($curl, CURLOPT_URL, $the_site);
      curl_setopt($curl, CURLOPT_COOKIE, '/cookie.txt');
      curl_setopt($curl, CURLOPT_FILE, $fp);
  
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  
      $http_headers = array(
          'Host: www.lynda.com',
          'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
          'Accept: */*',
          'Accept-Language: en-us,en;q=0.5',
          'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7',
          'Connection: keep-alive'
      );
      curl_setopt($curl, CURLOPT_HEADER, true);
      curl_setopt($curl, CURLOPT_HTTPHEADER, $http_headers);
  
      curl_exec($curl);
  
  
  
      $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
      if($httpCode == 404)
      {
          touch('cache/404_err.txt');
      }
      else
      {
          $contents = curl_exec($curl);
          fwrite($fp, $contents);
      }
  
  
      curl_close($curl);
  }
  </code></pre>
  
  <p>I am on Windows 7 and running on this on WAMP.</p>
  
  <p>One of the things I am not sure about is if the "cookie.txt" file is getting read or not (not sure if the path is correct so I put the cookie.txt file in the root of the server as well as in the directory I am running this script from).</p>
  
  <p>Thanks in advance!</p>
  
  <p>----------- Found some code via the online manual ---------</p>
  
  <pre><code>// $url = page to POST data
  // $ref_url = tell the server which page you came from (spoofing)
  // $login = true will make a clean cookie-file.
  // $proxy = proxy data
  // $proxystatus = do you use a proxy ? true/false
  
  function
  curl_grab_page($url,$ref_url,$data,$login,$proxy,$proxystatus){
      if($login == 'true') {
          $fp = fopen("ryanCookie.txt", "w");
          fclose($fp);
      }
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_COOKIEJAR, "ryanCookie.txt");
      curl_setopt($ch, CURLOPT_COOKIEFILE, "ryanCookie.txt");
      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
      curl_setopt($ch, CURLOPT_TIMEOUT, 40);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
      if ($proxystatus == 'true') {
          curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
          curl_setopt($ch, CURLOPT_PROXY, $proxy);
      }
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_REFERER, $ref_url);
  
      curl_setopt($ch, CURLOPT_HEADER, TRUE);
      curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
      curl_setopt($ch, CURLOPT_POST, TRUE);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      ob_start();
      return curl_exec ($ch); // execute the curl command
      ob_end_clean();
      curl_close ($ch);
      unset($ch);
  }
  
  echo curl_grab_page("https://www.lynda.com/login/login.aspx", "http://www.lynda.com/", "simple_username=*******&amp;simple_password=*******", "true",  "null", "false")."done!";
  </code></pre>
  
  <p>But it still does not work :(
  This is the page where I got the above code: <a href="http://php.net/manual/en/function.curl-setopt.php" rel="nofollow">http://php.net/manual/en/function.curl-setopt.php</a></p>