Home > Backend Development > PHP Tutorial > Use php's fsocket to simulate get submission and simulate post submission form

Use php's fsocket to simulate get submission and simulate post submission form

WBOY
Release: 2016-07-25 08:45:18
Original
961 people have browsed it
  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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template