I need help with curl...

Discussion in 'PHP' started by Snix, Nov 16, 2007.

  1. #1
    Hi there,

    please if somebody can help me with a simple curl example, all i need is that the script to do the following:

    enter on a website - http://example.com/index.php
    get the cookies from that page
    save cookie to cookie.txt
    after that using the cookies enter on the http://exemple.com/newpage.php
    clear cookie from file.


    I will appreciate your help.

    Many Thanks
     
    Snix, Nov 16, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    (Untested)

    
    <?php
    
    $cookie_file = 'cookies.txt';
    $url_1 = 'http://example.com/index.php';
    $url_2 = 'http://exemple.com/newpage.php';
    
    $ch = curl_init($url_1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    
    // Go to first URL
    curl_exec($ch);
    curl_setopt($ch, CURLOPT_URL, $url_2);
    // Go to second
    curl_exec($ch);
    curl_close($ch);
    
    // Clear cookie file
    file_put_contents($cookie_file, null);
    
    ?>
    
    PHP:
     
    nico_swd, Nov 17, 2007 IP
  3. Snix

    Snix Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    First of all thank you for your help. Is not really what i'm looking but it is a start.

    On my home computer I have apache installed and every time when I open my browser I would like this script to open automatically the ebay page and log me in. I tried to modify this script for using ebay, but i receive an error that my browser is rejecting cookies.

    I found a script here: http://curl.haxx.se/libcurl/php/examples/ebay_login.html

    but it seems this in not working anymore, can you please take a look.

    Thanks
    Snix
     
    Snix, Nov 17, 2007 IP