<?php
$curl = curl_init();
$cookie_jar = tempnam('./tmp','cookie');
curl_setopt($curl, CURLOPT_URL,'http://www.ydma.cn/login');//这里写上处理登录的界面
$request = 'loginname=xxx&password=xxx';
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);//传 递数据
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);// 把返回来的cookie信息保存在$cookie_jar文件中
curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);//设定返回 的数据是否自动显示
curl_setopt($curl, CURLOPT_HEADER, false);//设定是否显示头信 息
curl_setopt($curl, CURLOPT_NOBODY, false);//设定是否输出页面 内容
$r=curl_exec($curl);//返回结果
// echo $r;
curl_close($curl); //关闭
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, 'http://www.ydma.cn/useraccount');//登陆后要从哪个页面获取信息
curl_setopt($curl2, CURLOPT_HEADER, false);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl2, CURLOPT_COOKIEFILE, $cookie_jar);
$content = curl_exec($curl2);
echo $content;
// curl_close($curl); //关闭
?>
<?php
header('Content-Type: text/html; charset=utf-8');
$cookie_file = dirname(__FILE__).'/cookie.txt';
//$cookie_file = tempnam("tmp","cookie");
//先获取cookies并保存
$url = "http://www.ydma.cn/login";
$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 = "loginname=345605334@qq.com&password=caopeng520'";
$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;
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, 'http://www.ydma.cn/userinfo');//登陆后要从哪个页面获取信息
curl_setopt($curl2, CURLOPT_HEADER, 0);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl2, CURLOPT_COOKIEFILE, $cookie_jar);
$content = curl_exec($curl2);
echo $content;
?>
<?php
$cookie_file=tempnam('./temp','cookie');
$login_url='http://bbs.php100.com/login.php';
$post_fields='loginname=345605334@qq.com&password=caopeng520';
$ch=curl_init($login_url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_fields);
curl_exec($ch);
curl_close($ch);
$url='http://www.ydma.cn/userinfo';
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
$content=curl_exec($ch);
preg_match("/<li>金钱:(.*)<\/li>/",$content,$arr);
echo $arr[1];
curl_close($ch);
?>