cURL登录填写表单但不“发布”

时间:2013-02-25 21:10:54

标签: php curl autologin

对于计算机科学项目,我们必须建立一个展示我们时间表的网站。所以基本上我们要做的就是登录this网站并从您指向的页面中获取信息。 我已经阅读了很多帖子,并尝试了很多cURL,但似乎没有任何工作。 我得到了要填写的表单,但看起来好像没有点击“提交”按钮。这就是我所拥有的:

<?php
$url="http://rooster.sgnphp.nl/infoweb/index.php"; 
$post_data['user'] = '105353';
$post_data['paswoord'] = '105353';

foreach ( $post_data as $key => $value) 
{
    $post_items[] = $key . '=' . $value;
}
$postdata = implode ('&', $post_items);

$ch = curl_init($url);
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.txt); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, cookie.txt); 
curl_setopt ($ch, CURLOPT_REFERER, $url); 
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$result = curl_exec ($ch); 
echo $result;

curl_close($ch);
?>

我试图填写的表格如下:

<form action="/infoweb/index.php" method="post">
<input type="hidden" name="csrf" value="cec30a2ed764e956ed01f137e2f0705a">
<table>
  <tbody><tr>
    <td>
      Gebruikersnaam:
    </td>
    <td>
      <input class="mooi" style="color: #FF8080;" type="text" name="user" value="105353" onfocus="if (this.value =='username') this.value=''; this.style.color='#000000';" onkeydown="this.style.color='#000000';">
    </td>
  </tr>
  <tr>
    <td>
      Wachtwoord:
    </td>
    <td>
      <input class="mooi" style="margin-bottom: 2px; color: #FF8080;" type="password"     name="paswoord" value="105353" onfocus="if (this.value =='wachtwoord') this.value=''; this.style.color='#000000';" onkeydown="this.style.color='#000000';">
    </td>
  </tr>
  <tr>
    <td>
      <input type="hidden" name="login" value="loginform"> &nbsp;
    </td>
    <td>
      <input type="submit" class="mooi" value="inloggen"><br>
    </td>
  </tr>
</tbody></table>
</form>

所以会发生什么是填写表格,但我看不到时间表,因为(我认为)我没有正式登录。 有人可以帮帮我吗?我真的需要让它工作,所以我可以继续我的项目的其余部分,但我已经坚持了几天。

由于

2 个答案:

答案 0 :(得分:0)

取决于登录脚本如何为该网站工作取决于您如何设置Curl。

乍一看,我猜你需要首先卷曲页面开始会话并保存cookie,然后删除“csrf”输入,然后发布你的用户名和密码。

从那时起,您可以卷曲任何需要您登录的链接。

如果“你”建立了网站,我相信你可以制作一个可以为你做这个的脚本吗?

答案 1 :(得分:0)

请注意,表单有一个隐藏的输入:

<input type="hidden" name="login" value="loginform">

您还需要发送此值:

$post_data['login'] = 'loginform';