php模拟登陆163邮箱失败,求解

php中文网
发布: 2016-06-20 12:37:45
原创
1556人浏览过

<?phpfunction curl($url,$cookiefile=0,$cookiejar=0,$httpheader=0,$referer="http://baidu.com",$follow=0,$header=1,$postdata=0,$cookiearr=array(),$proxy=0,$outtime=20000,$ua=0){		$ch = curl_init();		curl_setopt ( $ch, curlopt_nosignal,true);//开启毫秒超时		curl_setopt($ch, curlopt_timeout_ms, $outtime);//10s超时			curl_setopt($ch, curlopt_ssl_verifypeer, false);			curl_setopt($ch, curlopt_ssl_verifyhost, false);		curl_setopt($ch, curlopt_url,$url) ;		if($ua==0){			curl_setopt($ch, curlopt_useragent,'mozilla/5.0 (windows nt 10.0; wow64) applewebkit/537.36 (khtml, like gecko) chrome/31.0.1650.63 safari/537.36');		}else{			curl_setopt($ch, curlopt_useragent,$ua);		}		curl_setopt($ch, curlopt_referer, $referer);       //伪装referer		curl_setopt($ch, curlopt_header, $header);		if($httpheader){			curl_setopt($ch, curlopt_httpheader, $httpheader);		}		curl_setopt($ch, curlopt_returntransfer, 1);		curl_setopt ( $ch, curlopt_cookiesession, true );		if($follow){			curl_setopt($ch, curlopt_followlocation,$follow);//跟随重定向		}		//读取cookie		//foreach($cookiearr as $c){			//echo $c;		//	curl_setopt($ch,curlopt_cookie,$cookiearr[0]);		//}		if($cookiefile){			curl_setopt($ch, curlopt_cookiefile,$cookiefile);		}		if($postdata){			curl_setopt($ch, curlopt_post, 1);			curl_setopt($ch, curlopt_postfields, $postdata);		}else{			curl_setopt($ch, curlopt_customrequest, 'get');		}		 curl_setopt($ch, curlinfo_header_out, true);//开启返回请求头查看		//保存cookie		if($cookiejar){			curl_setopt($ch, curlopt_cookiejar, $cookiejar);		}		//代理		if($proxy){			curl_setopt($ch, curlopt_proxyauth, curlauth_basic); //代理认证模式			curl_setopt($ch, curlopt_proxy, $proxy['ip']); //代理服务器地址			curl_setopt($ch, curlopt_proxyport,$proxy['port']); //代理服务器端口			curl_setopt($ch, curlopt_proxytype, curlproxy_http); //使用http代理模式		}		$content=curl_exec($ch);		if($content === false){   			 $content= 'curl error: ' . curl_error($ch);		}		$info=curl_getinfo($ch);		$result[1]=$content;		$result[0]=$info;		curl_close($ch);		return $result;}//首次访问mail.163.com没有产生任何cookie/$url="https://mail.163.com/entry/cgi/ntesdoor?df=mail163_letter&from=web&funcid=loginone&iframe=1&language=-1&passtype=1&product=mail163&net=t&style=-1&race=468_528_417_gz&uid=qianxi770231@163.com";//貌似race参数是记录来源	$httpheader = array(		'cookie: starttime=1454514129882; logtype=; nts_mail_user=qianxi770231:-1:1; df=mail163_letter',	);//貌似starttime就是js里面的gettiem();//$postdata['savelogin']=1;$postdata['url2']="http://mail.163.com/errorpage/error163.htm";$postdata['username']="qianxi770231";//这邮箱可以使用$postdata['password']="ziyanpuye";$cookie ="cookie.txt";$content= curl($url,0,$cookie,$httpheader,"http://mail.163.com/",0,1,$postdata);print_r($content);//	echo $content[1];	$fp = @fopen("log.html", "w"); //记录捕获到的页面源码fwrite($fp,$content[1]); fclose($fp); 
登录后复制


//目前本人技术只能做到这里,,无法模拟成功登陆,
//上面的邮箱可以使用,,求好心人帮忙解决。。

凹凸工坊-AI手写模拟器
凹凸工坊-AI手写模拟器

AI手写模拟器,一键生成手写文稿

凹凸工坊-AI手写模拟器 359
查看详情 凹凸工坊-AI手写模拟器


回复讨论(解决方案)

参考:

<?php    header("Content-Type: text/html; charset=UTF-8");    error_reporting(0);    /**     * 登陆     * $user 163用户名     * $pass 密码    **/    function login($user,$pass){        //登陆        $url = 'http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1';              $cookie = tempnam('./cache/','~');//创建一个用于存放cookie信息的临时文件          $fields_post = array(            'username'      => $user,            'password'      => $pass,            'verifycookie'  => 1,            'style'         => -1,            'product'       => 'mail163',            'selType'       => -1,            'secure'        => 'on'        );         $fields_string = '';            foreach($fields_post as $key => $value){            $fields_string .= $key . '=' . $value . '&';        }            $fields_string = rtrim($fields_string , '&');        $headers = array(            'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0',            'Referer'    => 'http://www.163.com'        );        $ch = curl_init($url);          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//返回结果存放在变量中,而不是默认的直接输出        curl_setopt($ch, CURLOPT_HEADER, true);        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);//关闭连接时,将服务器端返回的cookie保存在以下文件中         curl_setopt($ch, CURLOPT_POST, true);        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);               $result= curl_exec($ch);        curl_close($ch);        preg_match_all('/<div class="info" id="eHint">(.*?) <\/div>/i', $result,$infos,PREG_SET_ORDER);        if(!empty($infos['0']['1'])){            unlink($cookie);            exit('<script type="text/javascript">alert("'.$infos['0']['1'].'");history.go(-1);</script>');        }else{                  $G_ROOT = dirname(__FILE__);            file_put_contents($G_ROOT.'/cache/cookie', $cookie);            return $cookie;        }    }    /**     *      * $data['url'] 请求地址     * $data['data_post'] post数据     * $data['cookie']     *    **/    function curl($data){        $url = $data['url'];        $data_post= $data['data_post']? $data['data_post']: false;        $cookie = $data['cookie'];              $headers = array(            'User-Agent'        => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0',            'Referer'    => 'http://www.163.com'        );        $ch = curl_init($url);           curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        curl_setopt($ch, CURLOPT_HEADER, true);        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);              curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);  //cookie文件 登陆之后         //POST 提交        if($data_post){            curl_setopt($ch, CURLOPT_POST, 1);            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_post);        }        $result = curl_exec($ch);        curl_close($ch);        return $result;    }
登录后复制

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号