简体   繁体   English

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

[英]PHP cURL: No error but impossible to login in submit form

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!). 我想登录“ https://webapp.wizards.com ”以下载页面,但是在输出中我获得了登录页面(并且没有错误!)。

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: 这是我的PHP代码:

$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);    
}  

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. 例如,在Chrome中,您可以使用:开发人员工具->网络->文档,查看提交表单时发生的情况。

By sniffing the login form at ttps://webapp.wizards.com/login.aspx I can see the following posted parameters: 通过在ttps://webapp.wizards.com/login.aspx上嗅探登录表单,我可以看到以下发布的参数:

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). 如果您的请求不包含这些参数,则Web应用程序很有可能会回退您的请求(通过再次显示页面并显示错误消息)。 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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM