php post数据,cookie程序

function socketData($host,$url,$headers='',$data){ $fp = @fsockopen($host, 80, $errno, $errstr, 30); if (!$fp) { return false; } else { $out = ($data?"POST":"GET")." ".$url." HTTP/1.1\r\n"; $out .= "Host: ".$host."\r\n"; $out .= $headers; $out .= "Connection: Close\r\n\r\n".$data; if(strlen($data)>=3){    $out .= 'Content-Length: '.strlen($data)."\r\n";     $out .= 'Content-Type: application/x-www-form-urlencoded'."\r\n";     } fwrite($fp, $out); $rtn = ""; while (!feof($fp)) { $rtn.= fgets($fp, 128); } fclose($fp); } //echo $rtn; $rtn=explode("\r\n\r\n",$rtn,2); $headerstr=explode("\r\n",$rtn[0]); //echo print_r($headerstr,1).'->'.__LINE__."<br/>\r\n"; $headers=array(); foreach($headerstr as $str) { $tmp=explode(':',$str,2); if(count($tmp)==2) { $headers[$tmp[0]]=trim($tmp[1]); } } if(isset($headers['Transfer-Encoding'])&&$headers['Transfer-Encoding']=='chunked') { $body=$rtn[1]; $rs=explode("\r\n",$body,2); $tmp=''; while(count($rs)==2) { $l=hexdec($rs[0]); if($l==0) break; $tmp.=substr($rs[1],0,$l); $body=substr($rs[1],$l+2); if($body=='') break; $rs=explode("\r\n",$body,2); } $rtn[1]=$tmp; } //Set-Cookie if($headers['Location']) { return ($headers['Set-Cookie']?"Set-Cookie: ".$headers['Set-Cookie']."\r\n":"").'Location: '.$headers['Location']; } return $rtn[1]; }


 

 

socketData('*.com.cn','/data/'.$_GET['id'].'.html',"Referer: http://*.html/r/n")

转载于:https://www.cnblogs.com/Iamlein/archive/2010/01/15/2375925.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值