0

我需要登录一个网页。我使用 CURL 和 post 登录,但这还不够。当您从网站登录时,该帖子还包含一个始终在变化的字符串。有没有办法克服它?

我用这个:

$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; he-IL; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);

$post = "username=$username&password=$password";
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

就像我需要代码才能真正访问网页并定期填写表格。

我到处找,但我能找到的只是使用发布数据。

谢谢!

4

1 回答 1

0

To pass that you need to visit the page with the form, grab the field and then use it in POST request when you submit the form.

I suggest you visit the form page not only for that, but also for the following reasons (some of which can be used to figure people using automatic requests):

  1. You recieve cookies
  2. You don't fake referrer, you actually visited the page
  3. You might want to check form fields to see if there's any new ones added since you wrote the script. That could be the case if form setup changes and you might want to adapt to that, if you don't then your script might stop working one day
于 2012-11-20T17:10:42.593 回答