cURL Post Question

Discussion in 'PHP' started by LazyD, May 8, 2007.

  1. #1
    So, im trying to learn cURL to post forms, etc.

    Ive read a couple tutorials and it seems like some add the form submit to the post string and some dont.

    I imagine you would need to, otherwise it wont actually complete posting the form. However, what is the correct format for doing so?

    Say you have <input type=submit name=btnSubmit value=Submit>

    Would the cURL post for that look like "....restofposthere....&btnSubmit=Submit"

    What if the btnSubmit doesnt have a value specified, how do you post that?
     
    LazyD, May 8, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    The value of btnSubmit is "Submit". However, if a field doesn't have a value, you can just leave it blank:

    foo=&bar=&foo1=bar1&...
     
    nico_swd, May 8, 2007 IP
  3. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Im sure this is a broad question, but does anyone know if its possible to login to CJ.Com via cURL?

    I found the login URL which is https://members.cj.com/member/foundation/memberlogin.do

    And it looks like it logs me in correctly but it says I need to transferred somewhere else and gives me a link on the page but doesnt redirect via cURL
     
    LazyD, May 8, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
    PHP:
     
    nico_swd, May 8, 2007 IP
  5. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    It wont let me use that command, its complaining about safe mode or opendir base...

    I managed to get in by using the home address and using a session id it generated... it looks like: https://members.cj.com/member/publisher/home.do;jsessionid=sessidhere

    That gets me to my homepage, ultimately I would like to get to a product page, the main goal is to be able to pull products into a format that I can insert into a database..

    Please be aware, this isnt mindless scraping, I have specific searches that still encompass a wide array of products...
     
    LazyD, May 8, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Ah, you should enable cookies as well.
    
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
    
    PHP:
     
    nico_swd, May 8, 2007 IP
  7. LazyD

    LazyD Peon

    Messages:
    425
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I did already, I guess my question is, is it possible to navigate web pages with cURL, or is it more useful for posting forms, etc.
     
    LazyD, May 8, 2007 IP