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. What Do I do?
<?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.
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.
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.
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.
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.
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.
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).
Huh, there has to be something, tried searching the source code for the text that appears after "Loading"?
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.
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.
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.
I want to extract the versions of both products located there. I guess there it is. How do I extract it?
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.