21,886
社区成员
发帖
与我相关
我的任务
分享
Host: www.xxx.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://author.xxsy.com/author_login.aspx
Cookie: ASP.NET_SessionId=ksk42e45hwdayz45uuse0s45;
Content-Type: application/x-www-form-urlencoded
Content-Length: 72
username=aaaaaaa&password=123123&verifycode=2613&step=dologin
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>采集</title>
</head>
<body>
<iframe id='img' src="verify.php" scrolling="No" frameborder="0"></iframe>
<form action="get.php" method="POST">
<input type="text" name="verifycode" />
<input type="submit" />
</form>
</body>
</html>
<?php
$url = 'http://www.xxx.com/inc/showCode.aspx';
$referer = 'http://www.xxx.com/';
echo doget($url,$referer,'');
function doget ( $url , $referer , $cookie )
{
$optionget = array ( 'http' => array ( 'method' => "GET" , 'header' => "User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.0.04506; CIBA)\r\nAccept:*/*\r\nReferer:" . $referer . "\r\nCookie:" . $cookie ));
$file = file_get_contents ( $url , false , stream_context_create( $optionget ));
return $file ;
}
?>
<?php
$data = array
(
'username' => '我的账号',
'password' => '我的密码',
);
$data['verifycode']=$_POST['verifycode']; //验证码
$data['step']= 'dologin'; //登陆动作标识符
$url = 'http://www.xxx.com/author_login.aspx'; //登陆地址
$referer = 'http://www.xxx.com/';
dologin($url,$data,$referer);
function dologin ( $url , $postdata , $referer ) // post获取cookie值用
{
$optionlogin = array ( 'http' => array ( 'method' => "POST" , 'header' => "User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.0.04506; CIBA)\r\nAccept:*/*\r\nReferer:" . $referer . "\r\nCookie:" . $cookie , 'content' => http_build_query($postdata, '', '&') ,));
$file = file_get_contents ( $url , false , stream_context_create( $optionlogin ));
//在返回的Header里面提取Cookie
preg_match_all( "/Set-Cookie:(.*?)\r\n/" , implode( "\r\n" , $http_response_header ), $cookies );
$cookies = implode( ";" , $cookies [1]);
print_r($cookies) ;
}
?>
$optionget = array ( 'http' => array (
'method' => "GET" ,
'header' => array(
"User-Agent:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.0.04506; CIBA)",
"Accept:*/*",
"Referer:" . $referer,
"Cookie:" . $cookie
)
));