zl程序教程

您现在的位置是:首页 >  后端

当前栏目

实现获取http内容的php函数分享

PHPHTTP 实现 函数 获取 分享 内容
2023-06-13 09:15:17 时间

复制代码代码如下:


<?php
functionhttp_open($url,$data,$cookie=null,$method="GET",$timeout=60){
 $options=array();
 $options["http"]["method"]=$method;
 $options["http"]["user_agent"]=$_SERVER["HTTP_USER_AGENT"];
 $options["http"]["timeout"]=$timeout;
 if($method=="POST"):
  $length=strlen($data);
  $options["http"]["header"]="Content-type:application/x-www-form-urlencoded\r\n".
  "Content-Length:{$length}\r\n".
  "P3P:CP=\"CURaADMaDEVaPSAoPSDoOURBUSUNIPURINTDEMSTAPRECOMNAVOTCNOIDSPCOR\"\r\n".
  "cookie:{$cookie}\r\n".
  "Connection:close\r\n";
  $options["http"]["content"]=$data;
 else:
  $options["http"]["header"]="Content-type:application/x-www-form-urlencoded\r\n".
  "P3P:CP=\"CURaADMaDEVaPSAoPSDoOURBUSUNIPURINTDEMSTAPRECOMNAVOTCNOIDSPCOR\"\r\n".
  "cookie:{$cookie}\r\n".
  "Connection:close\r\n";
 endif;

 $context=stream_context_create($options);
 returnfile_get_contents($url,0,$context);
}
echohttp_open("http://localhost/1.php","username=haowei","id=5","POST");