PHP curl 模拟登陆 获取cookie求助
菜鸟学习使用PHP curl模拟登陆,等陆weiphon论坛时用以下代码成功,登陆www.xiaomi.com就死活成功不了,求助啊。窃以为是cookie获取有问题。麻烦牛人帮忙解决一下。苦思无所得夜不能寐啊!
<?php $cookie_file=tempnam('./temp','cookie'); $login_url='https://account.xiaomi.com/pass/serviceLoginAuth'; $post ='user&pwd=&sid=eshop&callback=http%3A%2F%2Forder.xiaomi.com%2Flogin%2Fcallback%3Ffollowup%3Dhttp%253A%252F%252Fwww.xiaomi.com%252F%26sign%3DMjk4NmVlYzNiOWY5YTkwMjExNzg5MjkyNzE3ZmIxOGM4YTBiMDk1Mg%2C%2C&_sign=f%2FKB8SAfmaLZ0s28kcLtBSmZlEM%3D&_json=true'//避免不必要的麻烦 post的具体帐号密码去掉了 $ch=$curl=curl_init($login_url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,0); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file); curl_setopt($ch,CURLOPT_POSTFIELDS,$post); curl_exec($ch); curl_close($ch); $url="http://www.xiaomi.com/index.php"; $ch=curl_init($url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,0); curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file); $contents=curl_exec($ch); curl_close($ch); ?>
回复讨论(解决方案)
把第十九行删除了
<?php $url="http://www.xiaomi.com/index.php"; $ch=curl_init($url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,0); //curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file); echo $contents=curl_exec($ch); curl_close($ch);
测试成功
可是这样就没达到模拟帐号登陆的效果呀。只是采集了xiaomi的主页。
那说明还有数据没有提交。例如:
curl_setopt($ch, CURLOPT_REFERER,
post的数据不全:
两周内自动登录的input标志:auto=1
网页里面表单的其它值等。
$login_url='https://account.xiaomi.com/pass/serviceLoginAuth';
应为:
$login_url='https://account.xiaomi.com/pass/serviceLoginAuth2';
<form method="post" action="/pass/serviceLoginAuth2" id="loginForm" onsubmit="return validate_form()"> <input type="hidden" name="passToken" id="passToken" value="" /> <div class="input-field clearfix" id="loginId"> <input type="text" id="user_ph" class="input_kuang item errortip" value="邮箱/手机号码/小米ID" style="color:#999;display:none;"/> <input type="text" name="user" value="" id="user" class="input_kuang item errortip" placeholder="邮箱/手机号码/小米ID" isRequired="true" rule="(^[\w.\-]+@(?:[a-z0-9]+(?:-[a-z0-9]+)*\.)+[a-z]{2,6}$)|(^1[3|4|5|8]\d{9}$)|(^\d{3,}$)|(^\++\d{2,}$)" autocomplete="off"/> <span class="littlepop"><!-- 错误提示小气泡 --> <span class="popmessage error_tip"> <span class="error_icontwo"></span><span id="errorTip">帐户名错误</span> </span> <span class="popmessage empty_tip"> <span class="error_icontwo"></span><span>请输入帐户名</span> </span> <i class="little_corner"></i> </span> </div> <div class="input-field clearfix" id="loginPass"> <input type="text" id="pwd_ph" value="密码" class="input_kuang item errortip" style="color:#999;display:none;"/> <input type="password" name="pwd" class="input_kuang item errortip" id="pwd" placeholder="密码" isRequired="true" autocomplete="off"/><!-- error_put为出现错误时的黄框 --> <span class="littlepop"> <span class="popmessage empty_tip"> <span class="error_icontwo"></span><span>请输入密码</span> </span> <i class="little_corner"></i> </span> <input type="hidden" name="callback" value="https://account.xiaomi.com"> <input type="hidden" name="sid" value="passport"> <input type="hidden" id="qs" name="qs" value="%3Fsid%3Dpassport"/> <input type="hidden" name="hidden" value=""> <input type="hidden" name="_sign" value="KKkRvCpZoDC+gLdeyOsdMhwV0Xg="> </div> <div class="cooke"> <label for="auto"><input type="checkbox" id="auto" name="auto" value="true" class="Mradio val_mT" /><span class="val_m">两周内自动登录</span></label> </div> <div class="sub_log clearfix"> <div class="sub_login flt_l"><input type="submit" class="no_bg" value="登录"/></div> <a href="/pass/forgetPassword">忘记密码?</a> </div> </form>
里面所有 的值,其中passToken可能是使用js生成的。
感谢大神提供思路,我再试试看~

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...
