1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Urgent : cURL problems

Discussion in 'PHP' started by RxDx, Jul 24, 2010.

  1. #1
    Hello,

    I need a script that would be logging itself on a page and doing some actions there.
    I have username and password, I need the script to insert those into fields and log-in.
    This is a first problem. How do I implement that it would log itself in?

    Then, second problem.
    The page with log-in and after user logged in(member page) has some AJAX on it, which says : Loading.
    file_get_contents does not work properly as it loads only Loading, but not actual content.
    SEMrush
    What Do I do?
     
    RxDx, Jul 24, 2010 IP
    SEMrush
  2. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #2
    <?php
    $ch = curl_init(); // Start cURL session
    curl_setopt($ch, CURLOPT_URL, "http://location.us/loginAction.php"); // Set the URL
    curl_setopt($ch, CURLOPT_POSTFIELDS, "username=fjodor&pass=kittycat"); // Set POST data (when CURLOPT_POSTFIELDS is set, CURLOPT_POST is not needed any more in my experience)
    curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null"); // Set location for storing cookie (remember, cookieJAR stores, cookieFILE accesses)
    curl_exec($ch); // Execute
    
    curl_setopt($ch, CURLOPT_URL, "http://location.us/memberArea.php"); // Set the new URL
    curl_setopt($ch, CURLOPT_COOKIEFILE, "/dev/null"); // Set cookie location
    curl_exec($ch); // Execute
    curl_close($ch); // Close cURL handle
    ?>
    PHP:
    This code will perform a POST action in the first part and store the cookie information.
    In the second part, it's going to use the cookie information to access the protected area.

    Oh and for the second part, use SmartSniff (best packet sniffer imho) to find out which page the Ajax function really accesses.
    Just start the sniffer, load the page and see which URLs are accessed during the page load.
     
    Last edited: Jul 24, 2010
    iAreCow, Jul 24, 2010 IP
  3. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello, thank you for reply!

    The code you provided me with says Loading 2x times. I am not sure it logged in correctly because Ajax is messing everything up. It is also used on the login page.

    I also downloaded the sniffer and it does show me a php page with a brutal name and with .cache in it. I opened it and it has lots of different functions... But no actual code.
     
    RxDx, Jul 24, 2010 IP
  4. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Add the following line (after the cookie line, lets say) in order to prevent output to client (it allows storing the output in a variable, if you set one for curl_exec()):
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    PHP:
    Then there has to be more than one page that's being loaded with the Ajax function, try reviewing the whole list in SmartSniff window.
     
    iAreCow, Jul 24, 2010 IP
  5. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Did it, now my page is blank(sorry to confuse you, there was Loading 1 time only. The second was my fault, I tried file_get_contents and forgot to delete it).

    The Sniffer now shows some .js file which, again, has lots of things inside, but not content.
     
    RxDx, Jul 24, 2010 IP
  6. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Change the last curl_exec($ch); to $resource = curl_exec($ch); and ensure you have the returntransfer line in the last block of code. Then you can do echo $resource; to display the page.

    The .js file should be JavaScript source code, which also contains functions and other stuff needed for loading the page properly. See, the SmartSniff window has an Index tab, there will be numbers, starting from 1 and ending at some point. Try reviewing ALL the numbers for some possible .php ending pages.
     
    iAreCow, Jul 24, 2010 IP
  7. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Changed it, now it displays Loading.
    I looked in .js file, it looks heavily encrypted. I also looked all reports in SmartSniff, no pages ending with php were seen, except for his cache page.
     
    RxDx, Jul 24, 2010 IP
  8. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #8
    Hmm, if it's Base64 encrypted, you're lucky, try decoding the script with base64_decode() function. If it still looks encoded, do it a few more times (some guy used base64_encode() a dozen times, so it took some time to figure out).
     
    iAreCow, Jul 24, 2010 IP
  9. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Hmm, it has lots of different functions inside.
     
    RxDx, Jul 24, 2010 IP
  10. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #10
    Oh, then you should look for some sort of file or URL it's trying to access.
     
    iAreCow, Jul 24, 2010 IP
  11. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    There's nothing even close to that :(
     
    RxDx, Jul 24, 2010 IP
  12. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #12
    Huh, there has to be something, tried searching the source code for the text that appears after "Loading"?
     
    iAreCow, Jul 24, 2010 IP
  13. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    There is nothing after that. Ending divs and closing HTML tags.
    There is also some JS script before that. Part of it is encoded, other has some words, like Download, Version etc. I tried decoding first part, it returns mumbo jumbo, some characters from other encoding or something like that.
     
    RxDx, Jul 24, 2010 IP
  14. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #14
    Huh, could you share the script over Paste2.org, so me and others could have a look?
     
    iAreCow, Jul 24, 2010 IP
  15. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    http: //paste2. org/p/926178 this is script of login page
     
    RxDx, Jul 24, 2010 IP
  16. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #16
    Doesn't look like encoded to me, what do you need extracted anyway?
     
    iAreCow, Jul 24, 2010 IP
  17. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    I need to log myself in, meaning put my username and pass to login, then extract a bit of information from the members area.
    I tried your code, but it only says Loading application. The code for this is seen in the script of login page I gave.

    I don't know whether it logged in, or whether it is still on login page, since Loading application appears in members area aswell.
     
    RxDx, Jul 24, 2010 IP
  18. iAreCow

    iAreCow Peon

    Messages:
    85
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #18
    It should login fine if POST data is correct, but see the source code of the page that keeps "Loading" and see if everything you need is there, if it is, it can be extracted.
     
    iAreCow, Jul 24, 2010 IP
  19. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I want to extract the versions of both products located there. I guess there it is.
    How do I extract it?
     
    RxDx, Jul 24, 2010 IP
  20. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    I also tried logging in to a page where there is no Ajax, the code does not work for some reason. I tried your variant as well as putting real field names instead of username and pass.
     
    RxDx, Jul 24, 2010 IP