[PHP] PHP fsockopen模拟POST/GET方法 →→→→→进入此内容的聊天室

来自 , 2019-12-18, 写在 PHP, 查看 159 次.
URL http://www.code666.cn/view/d60678e8
  1. //fsocket模拟post提交
  2. $url = "http://localhost/test2.php?site=yuncode.net";
  3.  
  4. //echo $query;
  5. sock_get($url,"user=gonn");
  6. //sock_get($url, $query);
  7.  
  8. //fsocket模拟get提交
  9. function sock_get($url, $query)
  10. {
  11.         $data = array(
  12.         'foo'=>'bar',
  13.         'baz'=>'boom',
  14.         'site'=>'yuncode.net',
  15.         'name'=>'nowa magic');
  16.        
  17.         $query_str = http_build_query($data);
  18.        
  19.     $info = parse_url($url);
  20.     $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
  21.     //$head = "GET ".$info['path']."?".$info["query"]." HTTP/1.0\r\n";
  22.         $head = "GET ".$info['path']."?".$query_str." HTTP/1.0\r\n";
  23.     $head .= "Host: ".$info['host']."\r\n";
  24.     $head .= "\r\n";
  25.     $write = fputs($fp, $head);
  26.     while (!feof($fp))
  27.     {
  28.         $line = fread($fp,4096);
  29.         echo $line;
  30.     }
  31. }
  32.  
  33. sock_post($url,"user=gonn");
  34.  
  35. function sock_post($url, $query)
  36. {      
  37.     $info = parse_url($url);
  38.     $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
  39.     $head = "POST ".$info['path']."?".$info["query"]." HTTP/1.0\r\n";
  40.     $head .= "Host: ".$info['host']."\r\n";
  41.     $head .= "Referer: http://".$info['host'].$info['path']."\r\n";
  42.     $head .= "Content-type: application/x-www-form-urlencoded\r\n";
  43.     $head .= "Content-Length: ".strlen(trim($query))."\r\n";
  44.     $head .= "\r\n";
  45.     $head .= trim($query);
  46.     $write = fputs($fp, $head);
  47.     while (!feof($fp))
  48.     {
  49.         $line = fread($fp,4096);
  50.         echo $line;
  51.     }
  52. }
  53.  

回复 "PHP fsockopen模拟POST/GET方法"

这儿你可以回复上面这条便签

captcha