具体网站具体分析
分类:热门新闻

艺术1用curl:一.先开启php curl函数库的手续1State of Qatar.去掉windows/php.ini 文件里;extension=php_curl.dll前面的; /*用 echo phpinfo();查看php.ini的路径*/2卡塔尔(قطر‎.把php5/libeay32.dll,ssleay32.dll复制到系统目录windows/下3卡塔尔(قطر‎.重启apache二.例子例子:?php$cookie_jar=tempnam(''./tmp'',''cookie'');$ch=curl_init();curl_setopt($ch,CURLOPT_URL,''******'');curl_setopt($ch,CURLOPT_POST,1);$request=''email_address=password=action='';curl_setopt($ch,CURLOPT_POSTFIELDS,$requestState of Qatar;//把重临来的cookie音讯保存在$cookie_jar文件中curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_jar卡塔尔国;//设定再次来到的数据是或不是自动展现curl_setopt($ch,CURLOPT_RETUSportageNTRANSFEEnclave,1State of Qatar;//设定是或不是出示头消息curl_setopt($ch,CURLOPT_HEADEOdyssey,false卡塔尔(قطر‎;//设定是还是不是输出页面内容curl_setopt($ch,CURLOPT_NOBODY,false);curl_exec($ch);curl_close($ch);//getdataafterlogin$ch2=curl_init();curl_setopt($ch2,CURLOPT_URL,''*****'');curl_威尼斯登录首页,setopt($ch2,CURLOPT_HEADER,false);curl_setopt($ch2,CURLOPT_RETURNTRANSFER,1);curl_setopt($ch2,CURLOPT_COOKIEFILE,$cookie_jar);$orders=curl_exec($ch2);echo'''';echostrip_tags($orders);echo'''';curl_close($ch2);?方法2用fsockopen:?phpfunctionGetWebContent($host,$method,$str,$sessid=''''){$ip=gethostbyname($host);//echoip=$ipbr;[email=$fp=@fsockopen($ip,80]$fp=@fsockopen($ip,80[/email]);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- State of Qatar;fputs($fp,Content-Type:application/x- 卡塔尔;fputs($fp,User-Agent:Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.1;SV1;InfoPath.1卡塔尔(قطر‎卡塔尔国卡塔尔;//addbyEw071012fputs($fp,Connection:Keep-Alive );if(substr(trim($method卡塔尔,0,4卡塔尔(قطر‎==POSTState of Qatar{fputs($fp,$str. 卡塔尔国;}while(!feof($fp)){$response.=fgets($fp);}$hlen=strpos($response, );//LINUX下是 $header=substr($response,0,$hlen);//echoheader=$headerhrhr;$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;}$response=GetWebContent($host,POST/$login_pageHTTP/1.0,$str卡塔尔国;//登陆得到新的session_id//...能够在那先保存session_id$response=GetWebContent($host,GET/$somepageHTTP/1.0,'''',$response[''sessid'']);//使用session_id访谈页面echo$response[''location''].$response[''content''].br;?<

时不常会有人问模拟登入的主题材料,其实原理很简短,只要把SessionID保存下去就可以了,前几天花了一个钟头的光阴写了叁个函数,供我们参考,网址重回的头新闻,具体网址具体解析。

  源代码:

<?php
/*
* 获得网页内容
* 参数:$host [in] string
* 主机名称(比如: www.etoow.com)
* 参数:$method [in] string
* 提交方法:POST, GET, HEAD ... 并加上相应的参数( 具体语法参见 奥迪Q7FC壹玖肆叁,XC60FC2068 卡塔尔国
* 参数:$str [in] string
* 提交的剧情
* 参数:$sessid [in] string
* PHP的SESSIONID
*
* @再次回到 网页内容 string
*/
function GetWebContent($host, $method, $str, $sessid = '')
{
$ip = gethostbyname($host);
$fp = fsockopen($ip, 80);
if (!$fp) return;
fputs($fp, "$methodrn");
fputs($fp, "Host: $hostrn");
if (!empty($sessid))
{
fputs($fp, "Cookie: PHPSESSID=$sessid; path=/;rn");
}
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, "Content-Length: ". strlen($strState of Qatar . "rn"卡塔尔; // 别忘了内定长度
}
fputs($fp, "Content-Type: application/x-www-form-urlencodedrnrn");
if ( substr(trim($method),0, 4) == "POST")
{
fputs($fp, $str."rn");
}
while(!feof($fp))
{
$response .= fgets($fp, 1024);
}
$hlen = strpos($response," "); // LINUX下是 " "
$header = substr($response, 0, $hlen);
$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;
}

/* 结构顾客名,密码字符串 */
$str = ("username=test&password=test");
$response = GetWebContent("localhost","POST /login.php HTTP/1.0", $str);
echo $response['location'].$response['content']."<br>";
echo $response['sessid']."<br>";
if ( preg_match('/error.php/i',$response['location']))
{
echo "登录失利<br>";
} else {
echo "登入成功<br>";
// 不得以访谈user.php,因为不带sessid参数
$response = GetWebContent("localhost","GET /user.php HTTP/1.0", '', '');
echo $response['location']."<br>"; // 结果:error.php?errcode=2

// 能够访谈user.php
$response = GetWebContent("localhost","GET /user.php HTTP/1.0", '', $response['sessid']);
echo $response['location']."<br>"; // 结果:user.php
}
?>

本文由威尼斯在线注册平台发布于热门新闻,转载请注明出处:具体网站具体分析

上一篇:Win二零零四设置Apache PHP4 MySQL 下一篇:鉴于为了宽容性而放置的 embed 标签是不相符 W3C
猜你喜欢
热门排行
精彩图文