<?
function GetWebContent($host, $method, $str, $sessid = '')
{
$ip = gethostbyname($host);
$fp=@fsockopen($ip,80);
if (!$fp) return;
fputs($fp, "$method ");
fputs($fp, "Host: $host ");
if (!empty($sessid))
{
fputs($fp, "Cookie: PHPSESSID=$sessid; path=/; ");
}
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, "Content-Length: ". strlen($str) . " "); // 别忘了指定长度
}
//fputs($fp, "Content-Type: application/x-www-form-urlencoded ");
fputs($fp, "Content-Type: application/x-www-form-urlencoded ");
fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1) )");//add by Ew 071012
fputs($fp, "Connection: Keep-Alive ");
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, $str." ");
}
while(!feof($fp))
{
$response .= fgets($fp);
}
$hlen = strpos($response," "); // LINUX下是 " "
$header = substr($response, 0, $hlen);
//echo "header=$header<hr><hr>";
$entity = substr($response, $hlen + 4);
if ( preg_match('/PHPSESSID=([0-9a-z]+);/i', $header, $matches))
{
$a['sessid'] = $matches[1];
}
if ( preg_match('/Location: ([0-9a-z\_\?\=\&\#\.]+)/i', $header, $matches))
{
$a['location'] = $matches[1];
}
$a['content'] = $entity;
fclose($fp);
return $a;
}
?>
函数描述及例子
$host = "www.xmcase.com";
$login_page = "/demo/guestbook.php";
$str = "act=add&author=30&email=haha@haah.com&subject=13584451245&content=imageField";
$response = GetWebContent("$host","POST /$login_page HTTP/1.0", $str);//登入得到新的session_id
//$response = GetWebContent("$host","GET /$login_page HTTP/1.0", '', $response['sessid']);//使用session_id访问页面
//print_r($response);
exit;
function GetWebContent($host, $method, $str, $sessid = '')
{
$ip = gethostbyname($host);
$fp=@fsockopen($ip,80);
if (!$fp) return;
fputs($fp, "$method ");
fputs($fp, "Host: $host ");
if (!empty($sessid))
{
fputs($fp, "Cookie: PHPSESSID=$sessid; path=/; ");
}
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, "Content-Length: ". strlen($str) . " "); // 别忘了指定长度
}
//fputs($fp, "Content-Type: application/x-www-form-urlencoded ");
fputs($fp, "Content-Type: application/x-www-form-urlencoded ");
fputs($fp, "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.1) )");//add by Ew 071012
fputs($fp, "Connection: Keep-Alive ");
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, $str." ");
}
while(!feof($fp))
{
$response .= fgets($fp);
}
$hlen = strpos($response," "); // LINUX下是 " "
$header = substr($response, 0, $hlen);
//echo "header=$header<hr><hr>";
$entity = substr($response, $hlen + 4);
if ( preg_match('/PHPSESSID=([0-9a-z]+);/i', $header, $matches))
{
$a['sessid'] = $matches[1];
}
if ( preg_match('/Location: ([0-9a-z\_\?\=\&\#\.]+)/i', $header, $matches))
{
$a['location'] = $matches[1];
}
$a['content'] = $entity;
fclose($fp);
return $a;
}
?>
函数描述及例子
$host = "www.xmcase.com";
$login_page = "/demo/guestbook.php";
$str = "act=add&author=30&email=haha@haah.com&subject=13584451245&content=imageField";
$response = GetWebContent("$host","POST /$login_page HTTP/1.0", $str);//登入得到新的session_id
//$response = GetWebContent("$host","GET /$login_page HTTP/1.0", '', $response['sessid']);//使用session_id访问页面
//print_r($response);
exit;
相关文章
[错误报告] [推荐] [收藏] [打印] [关闭] [返回顶部]


已有