电脑安全

您当前的位置:主页 > 电脑安全 >

php模拟登录 获取SESSIONID,并则在读取网页的时候

来源:[db:来源]标题:   例子    编辑:电脑技术全能网 时间:2019-09-18 17:59

原标题:php模拟登录 获取SESSIONID,并则在读取网页的时候
   方式1用curl:一.先开启php curl函数库的步调1).去掉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,''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);//getdataafterlogin$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'''';echostrip_tags($orders);echo'''';curl_close($ch2);?>方式2用fsockopen:<?phpfunctionGetWebContent($host,$method,$str,$sessid=''''){$ip=gethostbyname($host);//echo"ip=$ip<br>";[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-www-form-urlencoded ");fputs($fp,"Content-Type:application/x-www-form-urlencoded ");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)=="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;}$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>";?><

上一篇:php的缓存类-网络编程

下一篇:没有了