WEB cURL help

Discussion in 'OT Technology' started by Krakerjak, May 21, 2009.

  1. Krakerjak

    Krakerjak Active Member

    Joined:
    Jul 7, 2003
    Messages:
    8,288
    Likes Received:
    0
    Location:
    Edmonton eh
    cURL help -- or alternatives

    ********Got it working, :bowdown: to me.
    Code:
    <?
    require_once('livestrong_xls_query.inc');
    
    curl_http_request('http://www.livestrong.com/login/', array(
        'CURLOPT_POST'               => true,
        'CURLOPT_FOLLOWLOCATION'     => true,
        'CURLOPT_POSTFIELDS'         => 'login_username=***********&login_password=*************&submit=Sign+In',
        'CURLOPT_RETURNTRANSFER'     => true,
        'CURLOPT_USERAGENT'          => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
        'CURLOPT_COOKIEJAR'          => 'htdocs/xlsreader/cookie.txt',
        'CURLOPT_COOKIEFILE'         => 'htdocs/xlsreader/cookie.txt'
    ));  
    
    $url = livestrong_xls_query();
    $fp = fopen("success.xls", "w");
    
    curl_http_request($url, array(
        'CURLOPT_RETURNTRANSFER'        => true,
        'CURLOPT_FOLLOWLOCATION'        => true,
        'CURLOPT_FILE'                  => $fp,
        'CURLOPT_USERAGENT'             => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
        'CURLOPT_COOKIEJAR'             => 'htdocs/xlsreader/cookie.txt',
        'CURLOPT_COOKIEFILE'            => 'htdocs/xlsreader/cookie.txt'
    ));  
    fclose($fp);
    
    /*
    * Coded By: Chad Scira (if you remove this, you will spontainously combust)
    *
    * Gives you the ability to run a full blown CURL call with just a url and an array
    *
    * @var    string
    * @var    array
    */
    function curl_http_request ($url, $options)
    {
        $handle = curl_init($url);
        foreach ($options as $option => $value) curl_setopt($handle, constant($option), $value);
        ob_start();
        $buffer = curl_exec($handle);
        ob_end_clean();
        curl_close($handle);
        return $buffer;
    }  
    
    ?>
     
    Last edited: May 24, 2009
  2. Krakerjak

    Krakerjak Active Member

    Joined:
    Jul 7, 2003
    Messages:
    8,288
    Likes Received:
    0
    Location:
    Edmonton eh
    curl is driving me crazy.

    I suppose there are other ways I could do this, I just don't know them.
    My main goal is to be able retrieve the .xls file from that site according to the date parameters I pass to that url...
    start_Month=mm
    start_Day=dd
    start_Year=yyyy
    end_Month=mm
    end_Day=dd
    end_Year=yyyy

    usually accomplished using a form submission, like they have on their site.

    I just don't want to have to login over there, fill out the form, save the file, upload it to my server, and process it. Ideally I would could use cron and curl to grab updates at regular intervals. If not I at least want to make a small form on my site, grab the file and update the data on my site on submit.
    Is curl the way to go?
     
  3. Krakerjak

    Krakerjak Active Member

    Joined:
    Jul 7, 2003
    Messages:
    8,288
    Likes Received:
    0
    Location:
    Edmonton eh
    does drupal have a function to perform this operation?
    ..since im using drupal..

    :kingtoad:
     

Share This Page