Jump to content

Using CURL to fill out a simple form


Recommended Posts

 

I am trying to log into a web site and then download a csv file.  This is from my web hosting service and the only way to get my web logs is to manually log in and download.  This sucks. 

I want to automate the process.

 

After much reading it seems that curl is the way to go. 

    $gacookie="curl-1.txt";
    @touch($gacookie);
    @chmod($gacookie,0666);

    date_default_timezone_set('America/Chicago') ;

    $today = date('Ymd');


    $url='http://reports.llnw.com/?'; 
    $post = 'username=xx&password=xx&remember=on&login=Login'

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 10); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
    $login_result = curl_exec ($ch);
    curl_close($ch)


    $dataUrl = "http://reports.llnw.com/?&module=reporting&page=export&reportId=134318&timezone=America/Chicago"
    . "&startDate="
    . "$today"
    . "&endDate="
    . "$today"
    . "&exportSet=connections&exportType=csv";


    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 10); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
    $data = curl_exec($ch);
    curl_close($ch)

 

The above works just fine for the login  (at least it looks like it does) .... BUT I can not get the second url.

 

 

Any insight about how to properly use CURL or what I am doing wrong?

 

 

BTW I did a quickie in Perl and it works with the Mechanize pm so I know I have the parameters right.  Just want to use php for this one.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.