curl模拟登陆
编辑器加载中...
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/mayongzhan - 马永占,myz,mayongzhan
稍微有点水平的一看就能明白我讲的是啥吧...有的内容略...这个东西不能留下能直接用的.培养大家的开发能力. 去掉了关键注释
<?php
/**
* @name test.php
* @date Thu Jan 24 00:24:20 CST 2008
* @copyright 马永占(MyZ)
* @author 马永占(MyZ)
* @link http://blog.csdn.net/mayongzhan/
*/
header("Content-type: text/html;charset=utf-8");
$url = 'http://127.0.0.1/test/index4.php';
$post = 1;
$returntransfer = 1;
$port = 80;
$header = 0;
$nobody = 0;
$myz = rand(1,9);
$request = 'myz='.$myz.'&password=123';
$cookie_jar = tempnam('./tmp','cookie.txt');
$ch = curl_init();
$options = array(CURLOPT_URL => $url,
CURLOPT_HEADER => $header,
CURLOPT_NOBODY => $nobody,
CURLOPT_PORT => $port,
CURLOPT_RETURNTRANSFER => $returntransfer,
CURLOPT_POST => $post,
CURLOPT_POSTFIELDS => $request,
CURLOPT_COOKIEJAR => $cookie_jar
);
curl_setopt_array($ch, $options);
echo curl_exec($ch);
//print_r(curl_getinfo($ch));
curl_close($ch);
$ch2 = curl_init();
$options2 = array(CURLOPT_URL => $url,
CURLOPT_HEADER => $header,
CURLOPT_NOBODY => $nobody,
CURLOPT_PORT => $port,
CURLOPT_RETURNTRANSFER => $returntransfer,
CURLOPT_POST => $post,
CURLOPT_POSTFIELDS => $request,
CURLOPT_COOKIEFILE => $cookie_jar
);
curl_setopt_array($ch2, $options2);
echo curl_exec($ch2);
//print_r(curl_getinfo($ch));
curl_close($ch2);
//不使用CURLOPT_RETURNTRANSFER,结合ob也可以操作...反正这不是重点...
//ob_start("callback");
//echo "这里是页面的输出";
//ob_end_flush();
//function callback($buffer)
//{
// $buffer .= " --- by 马永占";
// file_put_contents('test.txt',$buffer);
// return "保存成功";
//}
?>