$cookie_jar = tempnam('./tmp','cookie');
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL, 'http://******');
curl_setopt($ch, CURLOPT_POST, 1);
$request = 'email_address=&password=&action=';
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //把返回来的cookie信息保存在$cookie_jar文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar); //设定返回的数据是否自动显示
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设定是否显示头信息
curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_exec($ch);
curl_close($ch); //get data after login
例二:
复制代码 代码如下:
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'http://*****');
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$orders = curl_exec($ch2);
echo '';
echo strip_tags($orders);
echo '';
curl_close($ch2); 实践证明很稳定:)
例三:
复制代码 代码如下:
set_time_limit(0);
function _rand() {
$length=26;
$chars = "0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
$string = '';
for($i = 0; $i < $length; $i++) {
$string .= $chars[mt_rand(0, $max)];
}
return $string;
}
$HTTP_SESSION=_rand();
echo $HTTP_SESSION;
$HTTP_Server="www.baidu.com";
$HTTP_URL="https://www.jb51.net/";
$ch = curl_init();
curl_setopt ($ch,CURLOPT_URL,"http://".$HTTP_Server.$HTTP_URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
//curl_setopt($ch,CURLOPT_COOKIE,$HTTP_SESSION);
$res = curl_exec($ch);
curl_close ($ch);
print_r($res);
刷论坛代码:
1、抓cookies程序:
复制代码 代码如下:
$URL="http://www.yoururl.com/bbs/login.asp?action=chk";
//填入论坛的登陆页面地址
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/login.asp");
//设置,访问页面的来源地址
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'username=→→敢死队→&password=168168');
//分析登陆页面,把用户名,密码分别对应起来
curl_setopt ($ch, CURLOPT_HEADER,true);
//使能显示http头,
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}
2、刷楼了:
复制代码 代码如下:
set_time_limit(0);
//设置程序执行时间无限制
$i=10000;
//耍10000次
for($j=0;$j<$i;$j++)
{
$URL="http://www.yoururl.com/bbs/savepost.asp";
//这个地址是回复表单里面action的url地址
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/dispbbs.asp?boardid=14&replyid=672709&id=127437&page=1&skin=0&Star=53");
//设置来源地址,如果不设置,论坛服务器有可能有验证不允许回复
curl_setopt($ch,CURLOPT_COOKIESESSION,true);
//能保存cookie
curl_setopt($ch,CURLOPT_COOKIE,"DvForum=userid=24122&usercookies=0&userhidden=2&password=w0reu3g775VrY745&userclass=%96%7C&username=%A1%FA%A1%FA%B8%D2%CB%C0%B6%D3%A1%FA&StatUserID=2194783945 ");
//这儿就是设置cookie了
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
//不显示内容,因为有很多论坛回复后要自动跳转。
curl_setopt($ch,CURLOPT_POSTFIELDS,'Body=gfdfgdfgasdfgdfgdfgdfg& followup=672709&RootID=127437&star=58&TotalUseTable=Dv_bbs3& amp;UserName=→→敢死队→&signflag=1&total=65535');
//把你分析的回复表单的参数分别赋值
curl_setopt ($ch, CURLOPT_HEADER,true);
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}
}
CURL相关函数