码迷,mamicode.com
首页 > Web开发 > 详细

cURL模拟网页登陆

时间:2016-07-14 21:09:46      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/7/13
 * Time: 23:15
 */
$data=username=71****11@qq.com&password=H***437&remember=1;
$curlobj = curl_init();            // 初始化
curl_setopt($curlobj, CURLOPT_URL, "http://www.imooc.com/user/login");        // 设置访问网页的URL
curl_setopt($curlobj, CURLOPT_RETURNTRANSFER, true);            // 执行之后不直接打印出来
curl_setopt($curlobj, CURLOPT_COOKIEFILE, cookiefile_hanks);
curl_setopt($curlobj, CURLOPT_COOKIEJAR, cookiefile_hanks);
curl_setopt($curlobj, CURLOPT_COOKIE, session_name() . = . session_id());
// Cookie相关设置,这部分设置需要在所有会话开始之前设置
date_default_timezone_set(PRC); // 使用Cookie时,必须先设置时区
curl_setopt($curlobj, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($curlobj, CURLOPT_HEADER, 0);
curl_setopt($curlobj, CURLOPT_FOLLOWLOCATION, 1); // 这样能够让cURL支持页面链接跳转
curl_setopt($curlobj, CURLOPT_POST, 1);
curl_setopt($curlobj, CURLOPT_POSTFIELDS, $data);
curl_setopt($curlobj, CURLOPT_HTTPHEADER, array("application/x-www-form-urlencoded; charset=utf-8", "Content-length: ".strlen($data)));
curl_exec($curlobj);    // 执行
curl_setopt($curlobj, CURLOPT_URL, "http://www.imooc.com/space/index");
curl_setopt($curlobj, CURLOPT_POST, 0);
curl_setopt($curlobj, CURLOPT_HTTPHEADER, array("Content-type: text/xml"
));
$output=curl_exec($curlobj);    // 执行
curl_close($curlobj);            // 关闭cURL
echo $output;

 

cURL模拟网页登陆

标签:

原文地址:http://www.cnblogs.com/719907411hl/p/5671562.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!