0

I have a script which logs into a website and im trying to update it to log into this other website but they have a scripted login box, not sure if its jquery/javascript or something but my usual script isnt working.

This is the site: http://uploaded.net, You click Login along the bottom and it pops up a little box.

The action of the form is action="io/login"

This is the script ive used in the past which worked for standard HTML login boxes.

$username="xxxxx"; 
$userpass="xxxxx"; 
$url="http://uploaded.net/#login"; 
$cookie="cookie.txt"; 


$postdata = "id=".$username."&pw=".$userpass."";

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$headers  = array();

$headers[] = 'application/xhtml+voice+xml;version=1.2, application/x-xhtml+voice+xml;version=1.2, text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1';
$headers[] = 'Connection: Keep-Alive';
$headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';

curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt ($ch, CURLOPT_HEADER, 1);
$result = curl_exec ($ch);
echo $result;

Anyone have an idea what i can do to login to this website using cURL?

Many Thanks

3
  • I've not looked at that page specifically, but try something like this? stackoverflow.com/a/18166859/2908724 Commented Nov 26, 2013 at 16:52
  • thats not PHP is it ? :( Commented Nov 26, 2013 at 16:52
  • No. AFAIK, if you need Javascript interaction, you're going to need a Javascript engine -- like node.js in that link. Commented Nov 26, 2013 at 17:06

1 Answer 1

1

try changing $url to

     $url="http://uploaded.net/io/login"; 

is the action of the form.

I've tested it and obtained an

HTTP/1.1 200 OK Server: nginx Date: Tue, 26 Nov 2013 19:00:55 GMT Content-Type: application/javascript; charset=ISO-8859-1 Content-Length: 41 Connection: keep-alive Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding

{"err":"User and password do not match!"}

I think it's better for you taking out

    curl_setopt ($ch, CURLOPT_HEADER, 1);

in order to get rid of headers in responses and make processing results step easier

Sign up to request clarification or add additional context in comments.

4 Comments

Hi thanks for the reply! i tried changing the URL to what you said and removing the line you mentioned but it dosen't seem to set the cookie in cookie.php and i have it to echo $result; but nothing is returned with you URL you suggested. Any ideas?
your code seems to work fine; it returns auth results (a failure, of course) and saves data in cookies.txt. Try close curl connection and/or check write permissions of the working directory.
Im running it on my PC, I used the same script with another login and it worked perfectly. The cookie.txt isnt read only so im assuming thats writeable? I never did anything special on my other script. I get a similar message to you but nothing goes into the cookie.txt file.
ok i added curl_close($ch); and it worked? Is that seriously why it wasn't working before :S Many thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.