欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php curl 模拟登录百度首页解决方案

程序员文章站 2022-05-17 13:48:29
...
php curl 模拟登录百度首页
代码如下:
PHP code
*/$post_fields = array();$post_fields = preg_data($contents,'aid',$post_fields);$post_fields = preg_data($contents,'isphone',$post_fields);$post_fields['mem_pass'] = 'on'; //post 数据数组  记住我的登录状态$post_fields = preg_data($contents,'more_param',$post_fields);$post_fields = preg_data($contents,'need_coin',$post_fields);$post_fields = preg_data($contents,'need_pay',$post_fields);$post_fields = preg_data($contents,'next_target',$post_fields);$post_fields['password'] = 'password'; //post 数据数组  记住我的登录状态$post_fields = preg_data($contents,'pay_method',$post_fields);$post_fields = preg_data($contents,'psp_tt',$post_fields);$post_fields = preg_data($contents,'return_method',$post_fields);$post_fields = preg_data($contents,'return_type',$post_fields);$post_fields = preg_data2($contents,'safeflg',$post_fields);$post_fields = preg_data($contents,'skip_ok',$post_fields);$post_fields = preg_data($contents,'tpl',$post_fields);$post_fields = preg_data($contents,'tpl_ok',$post_fields);$post_fields['u'] = 'http://www.baidu.com/';$post_fields['username'] = 'username'; //post 数据数组  记住我的登录状态$post_fields['verifycode'] = '';$ch = curl_init();curl_setopt ($ch, CURLOPT_URL, $url);curl_setopt ($ch, CURLOPT_HEADER, 0);curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt ($ch, CURLOPT_POST, 1);curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields);curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookdir);curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");curl_setopt ($ch, CURLOPT_REFERER, "https://passport.baidu.com/?login&tpl=mn");curl_exec($ch);curl_close($ch);$url = "http://www.baidu.com/";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookdir);curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");curl_setopt ($ch, CURLOPT_REFERER, "http://www.baidu.com/n");$contents = curl_exec($ch);print_r($contents);die;curl_close($ch);exit;function preg_data($source,$chr,$array){        preg_match('//i', $source, $matches);        if(!empty($matches)) {            $a = $matches[1];        } else {            die('Not found the '.$chr.'.');        }        $array[$chr]=$a;        return $array;}function preg_data2($source,$chr,$array){        preg_match('//i', $source, $matches);        if(!empty($matches)) {            $a = $matches[1];        } else {            die('Not found the '.$chr.'.');        }        $array[$chr]=$a;        return $array;}?>
php curl 模拟登录百度首页解决方案

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频