日期:2014-05-17  浏览次数:20677 次

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


?>


------解决方案--------------------
<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">