PHP CURL获取cookies模拟登录…
2017-11-14 16:24
661 查看
header('Content-Type: text/html; charset=utf-8');
$cookie_file = dirname(__FILE__).'/cookie.txt';
//$cookie_file = tempnam("tmp","cookie");
//先获取cookies并保存
$url =
"http://www.google.com.hk";
$ch =
curl_init($url); //初始化
curl_setopt($ch, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//返回字符串,而非直接输出
curl_setopt($ch, CURLOPT_COOKIEJAR,
$cookie_file); //存储cookies
curl_exec($ch);
curl_close($ch);
//使用上面保存的cookies再次访问
$url =
"http://www.google.com.hk/search?oe=utf8&ie=utf8&source=uds&hl=zh-CN&q=qq";
$ch =
curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//使用上面获取的cookies
$response = curl_exec($ch);
curl_close($ch);
echo
$response;
$cookie_file = dirname(__FILE__).'/cookie.txt';
//$cookie_file = tempnam("tmp","cookie");
//先获取cookies并保存
$url =
"http://www.google.com.hk";
$ch =
curl_init($url); //初始化
curl_setopt($ch, CURLOPT_HEADER, 0); //不返回header部分
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//返回字符串,而非直接输出
curl_setopt($ch, CURLOPT_COOKIEJAR,
$cookie_file); //存储cookies
curl_exec($ch);
curl_close($ch);
//使用上面保存的cookies再次访问
$url =
"http://www.google.com.hk/search?oe=utf8&ie=utf8&source=uds&hl=zh-CN&q=qq";
$ch =
curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
//使用上面获取的cookies
$response = curl_exec($ch);
curl_close($ch);
echo
$response;
相关文章推荐
- PHP中使用CURL模拟登录并获取数据实例
- PHP获取Cookie模拟登录CURL
- PHP获取Cookie模拟登录CURL
- PHP中使用CURL模拟登录并获取数据实例
- 使用PHP-curl获取验证码并模拟登录教务系统
- PHP获取Cookie模拟登录CURL(转)
- PHP通过CURL模拟登录并获取数据
- PHP获取Cookie模拟登录CURL
- PHP获取Cookie模拟登录CURL
- PHP获取Cookie模拟登录CURL
- PHP获取Cookie模拟登录CURL
- PHP中使用CURL模拟登录并获取数据实例
- PHP中使用CURL模拟登录并获取数据实例
- PHP模拟登录并获取数据
- php 使用curl模拟登录人人(校内)网
- 获取网页内容(不登录_PHP&.NET)
- PHP模拟登录并获取数据
- php 使用curl模拟登录discuz以及模拟发帖
- php模拟登录 获取SESSIONID,并则在读取网页的时候发送
- PHP使用CURL实现对带有验证码的网站进行模拟登录的方法