求助 php curl 模拟登陆 alimama?

ym12347 2013-10-17 10:43:19
function get($url)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
//打开呀里妈妈登陆页面
$url="http://www.alimama.com/member/minilogin.htm";
$add = get($url);

//得到页面中的一个随机值
preg_match("/<input name='_tb_token_' type='hidden' value='(.*)'>/isU",$add,$cadd);
#echo $cadd[1];
$cookie = dirname(__FILE__).'/cookie1.txt';
$surl='http://www.alimama.com/member/minilogin_act.htm';
$curlPost = "_tb_token_=".$cadd[1]." & logname=************* & logpasswd=********* & originalLogpasswd=********** & proxy=http://www.alimama.com/proxy.htm & redirect='' & style='' ";
$ch = curl_init($surl);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_exec($ch);
curl_close($ch);



求助 提交的数据有问题还是? 获取不到正确的cookie.
http://www.alimama.com/member/minilogin.htm
...全文
603 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
岑迅 2013-10-20
  • 打赏
  • 举报
回复
版里前段时间有个curl登录京东的 或许你们可以聊聊
ym12347 2013-10-19
  • 打赏
  • 举报
回复
求大神帮助啊。
xuzuning 2013-10-18
  • 打赏
  • 举报
回复
<input name='_tb_token_' type='hidden' value='fXVEewhq9fm'> <input type="hidden" name="style" value="" /> <input type="hidden" name="redirect" value="" /> <input type="hidden" name="proxy" value="" /> 后3个不提交是否可以?如果可以,他要他们做什么?
print_r(get_headers('http://www.alimama.com/member/minilogin.htm'));
Array ( [0] => HTTP/1.1 200 OK [1] => Server: Tengine [2] => Date: Fri, 18 Oct 2013 01:24:51 GMT [3] => Content-Type: text/html;charset=UTF-8 [4] => Connection: close [5] => Vary: Accept-Encoding [6] => Set-Cookie: cookie2=e06642156d5ce9afdaea41ce9294cae3;Domain=.alimama.com;Path=/;HttpOnly [7] => Set-Cookie: _tb_token_=6OWE4tYt9fm;Domain=.alimama.com;Path=/;HttpOnly [8] => Set-Cookie: t=b9e8101e83a7e0f0cafdd6296abb05a4; Domain=.alimama.com; Expires=Tue, 18-Jul-2023 02:04:51 GMT; Path=/ [9] => Set-Cookie: v=0; Domain=.alimama.com; Path=/ [10] => Content-Language: zh-CN [11] => Expires: Fri, 18 Oct 2013 01:24:51 GMT [12] => Cache-Control: max-age=0 ) 这几个 cookie 你也没有提交
iasky 2013-10-18
  • 打赏
  • 举报
回复
使用chrome的开发者工具来分析网络交互,主要就是看header和post等部分。
ym12347 2013-10-18
  • 打赏
  • 举报
回复
取回的有cookie的值,但是传入参数好像不够全 所以cookie 也是错的。
xuzuning 2013-10-18
  • 打赏
  • 举报
回复
CURLOPT_COOKIEJAR 是取回 cookie 到文件 CURLOPT_COOKIEFILE 是发送 cookie 文件(通常是上面取回的)
ym12347 2013-10-18
  • 打赏
  • 举报
回复
求版主指导, 对于cookie这块比较陌生。

20,395

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧