Take the 2-minute tour ×

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 :(

My code:


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',
        'Accept: */*',
        'Connection: keep-alive'
    curl_setopt($curl, CURLOPT_HEADER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $http_headers);


    $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    if($httpCode == 404)
        $contents = curl_exec($curl);
        fwrite($fp, $contents);


I am on Windows 7 and running on this on WAMP.

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).

Thanks in advance!

----------- Found some code via the online manual ---------

// $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

    if($login == 'true') {
        $fp = fopen("ryanCookie.txt", "w");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEJAR, "ryanCookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEFILE, "ryanCookie.txt");
    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_FOLLOWLOCATION, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    return curl_exec ($ch); // execute the curl command
    curl_close ($ch);

echo curl_grab_page("https://www.lynda.com/login/login.aspx", "http://www.lynda.com/", "simple_username=*******&simple_password=*******", "true",  "null", "false")."done!";

But it still does not work :( This is the page where I got the above code: http://php.net/manual/en/function.curl-setopt.php

share|improve this question
add comment

3 Answers

You need to understand how the internet and http work. You see, when you access a website, they usually give you cookies to track your status. You will also start as non logged-in member. After you hit login button, the server will update your status to logged-in and store this status, either in server site session or in your browser using cookies.

Back to your question, since you want to access member page, this mean, you need to do the following step by first, learn how lynda.com work. However, my step below is rather general:

  1. Load login page and get the form information
  2. inject form information with your login info and send the form back to server
  3. store cookies received from server
  4. load member page (don't forget to include cookies information from step 4) and fetch the html

For more information, you can look at this resources:

share|improve this answer
Please have a look at the added code on top. –  Ryan Nov 23 '12 at 7:28
add comment

Maybe you need to send Authorization header, which contain your username and password for the site in the HTTP header part.

share|improve this answer
add comment

To get the member page you need to login on the website. To do that, you need to:

  1. visit login page
  2. make the same request as your browser would do to submit login credentials
  3. fetch the member page

Alternatively, you could try to extract cookies from your browser after login and use them in curl with curl_setopt($ch, CURLOPT_COOKIE, 'a=b;c=d');, but this might not work as the website can also use IP or session check.

share|improve this answer
add comment

Your Answer


