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
https://forums.phpfreaks.com/topic/104930-using-curl-to-fill-out-a-simple-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.