Simulating Post data in PHP

Discussion in 'PHP' started by Malky, Apr 14, 2009.

  1. #1
    Let's say i want the contents of www.example.com/page.php, but it will not display the correct page until i login at www.example.com/ first.

    Basically there is one input box and a button, and i want to simulate typing something into that, then i want to grab the source code of that page.

    Could someone give me an example of this in php?
     
    Malky, Apr 14, 2009 IP
  2. logondotinfo

    logondotinfo Peon

    Messages:
    314
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #2
    probably not because the input box and button are most likely then handled by either the original file or a form handler before then redirecting onto page.php. The only way to do this would be to code something that will emulate a browser to trigger the form handler and allow itself to be redirected.
     
    logondotinfo, Apr 14, 2009 IP
  3. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need to post login data to the first page, save the cookies, then send them with your subsequent request. Curl is the best tool for this. There should be ample examples on the net.
     
    SmallPotatoes, Apr 14, 2009 IP
  4. fourfingers

    fourfingers Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, CURLOPT_POSTFIELDS will give you what you're looking for.

    Cookie support might not be necessary as some sites will use sessions to track your activity.
     
    fourfingers, Apr 17, 2009 IP
  5. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #5
    ActiveFrost, Apr 18, 2009 IP
  6. angielski

    angielski Peon

    Messages:
    57
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    If you expect it to be automatic without user involved, libcurl would be the best solution. But if you are just annoyed with your favourive webpage that makes you do that, you can use new firefox addons. You can record macros for some behaviours for specific websites.
     
    angielski, Apr 18, 2009 IP