当前位置:Gxlcms > PHP教程 > 用php的fsocket模拟get提交模拟post提交表单

用php的fsocket模拟get提交模拟post提交表单

时间:2021-07-01 10:21:17 帮助过:12人阅读

  1. //fsocket模拟post提交
  2. $purl = "http://www.baidu.com";
  3. print_r(parse_url($url));
  4. sock_post($purl, "parm=ping");
  5. //fsocket模拟get提交
  6. function sock_get($url, $query)
  7. {
  8. $info = parse_url($url);
  9. $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
  10. $head = "GET " . $info['path'] . "?" . $info["query"] . " HTTP/1.0rn";
  11. $head .= "Host: " . $info['host'] . "rn";
  12. $head .= "rn";
  13. $write = fputs($fp, $head);
  14. while (!feof($fp)) {
  15. $line = fread($fp, 4096);
  16. echo $line;
  17. }
  18. }
  19. sock_post($purl, "parm=ping");
  20. function sock_post($url, $query)
  21. {
  22. $info = parse_url($url);
  23. $fp = fsockopen($info["host"], 80, $errno, $errstr, 3);
  24. $head = "POST " . $info['path'] . "?" . $info["query"] . " HTTP/1.0rn";
  25. $head .= "Host: " . $info['host'] . "rn";
  26. $head .= "Referer: http://" . $info['host'] . $info['path'] . "rn";
  27. $head .= "Content-type: application/x-www-form-urlencodedrn";
  28. $head .= "Content-Length: " . strlen(trim($query)) . "rn";
  29. $head .= "rn";
  30. $head .= trim($query);
  31. $write = fputs($fp, $head);
  32. while (!feof($fp)) {
  33. $line = fread($fp, 4096);
  34. echo $line;
  35. }
  36. }
  37. ?>

php, fsocket, post

人气教程排行