我正在尝试登录具有以下格式的网站:
<div class="inner">
<form name="loginform" action="/site/?module=account&action=login&return_url=" method="post">
<input type="hidden" name="server" value="nice">
<div class="inputs">
<div class="user">
<input style="width: 108px;" id="login_user" type="text" name="username" value="username" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
</div>
<div class="pass">
<input style="width: 108px;" id="login_pass" type="password" name="password" value="password" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
<input type="submit" style="visibility:hidden"/>
</div>
</div>
<div class="submit">
<div class="submit-btn" onclick="document.loginform.submit();"></div>
</div>
<div class="clear"></div>
<div class="links">
<a href="/site/?module=account&action=resetpass">Forgot Password?</a>
</div>
</form>
</div>
使用这个php脚本:
<?php
$username="";
$password="";
$url="(handled this)";
$cookie="cookie.txt";
$postdata = "username=".$username."&password=".$password;
$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, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
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);
?>
将输出:
Invalid login server selected, please try again with a valid server.
因为我还没有满足隐藏的输入。 我尝试在谷歌搜索,但我看不到一个应该适用于它的PHP脚本。 对不起,当他们教cURL时,我在学校缺席。
答案 0 :(得分:0)
将服务器添加到$ postdata。
$postdata = "username=".urlencode($username)."&password=".urlencode($password)."&server=nice";
BTW:您需要对参数名称和参数值进行urlencode。