Jump to content

CURL - Can't log in b/c "key" field changes value


hatching

Recommended Posts

I'm using CURL to log in to access my data but they have a field that generates a new key everytime I reload the page.

 

My attempt was to extract the key value first, then include it to my postfield log in. When I do this, a new key has been generated making the extracted key useless.

 

 

<?php

  $curl_handle = curl_init($url);

  curl_setopt($curl_handle, CURLOPT_COOKIEFILE, 'cookie.txt');

  curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

  $buffer = curl_exec($curl_handle);

  curl_close($curl_handle);

  preg_match("/<input type=\"hidden\" name=\"key\" value=\"([a-zA-Z0-9]+)\" \/>/", $buffer, $match);

  $hiddenkey = $match[1];

 

  $fields_string = urlencode("email=EMAIL&passfield=PASS&pass=&attempts=&submit=Login&key=" . $hiddenkey);

 

 

  $curl_handle = curl_init($url);

  curl_setopt($curl_handle, CURLOPT_URL, $url);

  curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);

  curl_setopt($curl_handle, CURLOPT_COOKIEJAR, 'cookie.txt');

  curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $fields_string);

  curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, 1);

  $buffer = curl_exec($curl_handle);

  curl_close($curl_handle);

?>

Grab the contents of the login page.  Extract the key from the form.  Post username, password and key to log in.

 

If you are doing things in that order I dont see how they could generate a new key.

 

I tried doing what you are doing for a private torrent tracker site and gave up because it was too frustrating :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.