开发者

CURL grab information and log in with it

i got a problem. i want to log in a website with CURL, but the page generates a key, which is in a hidden field. So I have to grab the value of the hidden field... after that i have to submit the password, the email AND the the grabbed key.

Is that poss开发者_JAVA技巧ible?

hope you understand

Thanks

----edit---- if the page reload, there's a new key in the hidden field.. and the old one do not work


Yes, it's possible. The basic steps would be:

1. Fetch form
2. Run returned data through DOMdocument to extract the hidden form field's value
3. Post login data, including the key value from step #2
4. ???
5. Profit


Yes, it is.

  1. Load the page contents into a variable (eg. $contents = file_get_contents(...);).
  2. Now, parse it so you can get the hidden key (eg. $matches = preg_match(..., ...); $key = $matches[1];).
  3. Now, post the request using the hidden key (eg. $context = streamcontextcreate(...); $data = file_get_contents(..., false, $context);).


Yes, it is possible.

You can even grab the page with

$source = htmlspecialchars(file_get_contents($url));

Then use strpos, substr and so on to get information of that field (that's the easiest way)

Then just POST it with this function

$urltopost = $url

$datatopost = array ($name => $value);

$ch = curl_init ($urltopost);

curl_setopt ($ch, CURLOPT_POST, true);

curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$returndata = htmlspecialchars(curl_exec ($ch));

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜