0

我正在尝试登录具有以下表单的站点:

    <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 时我不在学校。

4

1 回答 1

0

将服务器添加到您的 $postdata。

$postdata = "username=".urlencode($username)."&password=".urlencode($password)."&server=nice";

顺便说一句:您需要对参数名称和参数值进行 urlencode。

于 2012-12-02T15:38:57.073 回答