<!-- curl的高级使用 --> <?php //模拟登陆获取cookie保存到电脑 header("content-Type: text/html; charset=UTF-8"); /*$cookie_file = tempnam(‘d:/‘, ‘cookie‘);*/ $cookie_file = ‘d:/demo.txt‘; $login_url="http://www.php-z.com/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=LJ0CC&inajax=1"; /*$post_fields="ormhash=354c7225&referer=http://www.php-z.com/&loginfield=username&username=chenglin1994&password=chenglin1994&questionid=0&answer=";*/ $post_fields =array(‘ormhash‘ => ‘354c7225‘, ‘referer‘ => ‘http://www.php-z.com/‘, ‘loginfield‘ => ‘username‘, ‘username‘ => ‘chenglin1994‘, ‘password‘ => ‘chenglin1994‘, ‘questionid‘ => ‘0‘, ‘answer‘ => ‘‘ ); //提交登录表单请求 $ch=curl_init($login_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,$cookie_file); //存储提交后得到的cookie数据 echo curl_exec($ch); curl_close($ch); //利用cookie查看个人中心 $url = ‘http://www.php-z.com/home.php?mod=space&do=friend‘; $ch=curl_init($url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file); //使用提交后得到的cookie数据做参数 $contents=curl_exec($ch); curl_close($ch); echo $contents;
关于curl的优秀文章
php curl cookie 存取示例(标准采集程序)及伪装
https://blog.csdn.net/e421083458/article/details/19326893
https://blog.csdn.net/e421083458/article/details/19326893
PHP cURL应用实现模拟登录与采集使用方法详解
http://www.cnblogs.com/Zjmainstay/p/php-curl.html
原文地址:https://www.cnblogs.com/cl94/p/9431909.html
时间: 2024-11-07 16:01:37