dongniuxia8650 2013-12-06 15:26
浏览 35
已采纳

PHP cURL:没有错误,但无法以提交表单登录

First, sorry for my english. I have read for a long time the other answers for this argument, but without success.

I want to login on "https://webapp.wizards.com" to download a page, but in output I obtain the login page (and no error!).

Thank you!

This is the login form:

<form name="loginform" id="loginform" action="login.aspx" method="POST">
<input type="hidden" name="target" value=""><BR>
<table cellpadding="0" cellspacing="0" class="boxsearch">
    <tr>
        <td align="left" class="boxtitles" width="355">Member Login</td>
    </tr>
    <tr>
        <td align="center" width="355" height="45">
            <table cellpadding="2" cellspacing="2" align="center" valign="middle" width="355">
                <tr>
                    <td align="right">Membership #:</td>
                    <td align="left">
                        <input type="text" name="dcinumber" id="dcinumber" value="" maxlength="10">
                    </td>
                </tr>
                <tr>
                    <td align="right">Password: </td>
                    <td align="left">
                        <input type="password" name="password" id="password" value="">
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <input type="button" name="submitlogin" id="submitlogin" class="submitbutton" value="Login" onclick="document.loginform.submit();">
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<input type="hidden" name="action" id="action" value="login">

And this my php code:

$cookie_path = "cookie.txt";    
$user = "my_user";    
$password = "my_password";    
$url_login = "https://webapp.wizards.com/login.aspx";

$con = curl_init();    
curl_setopt($con, CURLOPT_URL, $url_login);    
curl_setopt($con, CURLOPT_RETURNTRANSFER, true);    
curl_setopt($con, CURLOPT_SSL_VERIFYPEER, false);    
curl_setopt($con, CURLOPT_POST, true);    
curl_setopt($con, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)");    
curl_setopt($con, CURLOPT_COOKIEJAR, $cookie_path);    
curl_setopt($con, CURLOPT_COOKIEFILE, $cookie_path);    
curl_setopt($con, CURLOPT_FOLLOWLOCATION, true);    
curl_setopt($con, CURLOPT_COOKIESESSION, true);    
curl_setopt($con, CURLOPT_POSTFIELDS, array("dcinumber" => $user, "password" => $password));    
$data = curl_exec($con);    

if($data == false)    
{    
    echo 'Error: ' . curl_error($con);    
    curl_close($con);    
}    
else    
{        
    echo $data;    
    curl_close($con);    
}  
  • 写回答

1条回答 默认 最新

  • doupeng5320 2013-12-06 18:56
    关注

    When dealing remote form posts it is a really good idea to use a network sniffing tool so that you can see the communication taking place. For example in Chrome you could use: Developer Tools -> Network -> Documents, to view what is happening as you submit the form.

    By sniffing the login form at ttps://webapp.wizards.com/login.aspx I can see the following posted parameters:

    target: 
    dcinumber: 
    password: 
    action:login
    

    If your request does not contain these parameters it is very possible that the web application will throw back your request (by rendering the page again with an error message). This is why you see the login page in your result.

    So your post fields should look more like this:

    array("dcinumber" =>$user, "password" => $password, 'target' => $target, 'action' => 'login')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥20 win11无法启动 持续蓝屏且系统还原失败,无法开启系统保护
  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码