Home >Backend Development >PHP Tutorial >fsockopen access URL

fsockopen access URL

WBOY
WBOYOriginal
2016-07-25 08:49:211233browse
学习自alipay
  1. function gateway($url, $time_out="60") {
  2. $urlinfo = parse_url($url);
  3. $errno = "";
  4. $errstr = "";
  5. $transports = "";
  6. if ($urlinfo['scheme'] == "https") {
  7. $transports = "ssl://";
  8. $urlinfo['port'] = "443";
  9. }else{
  10. $transports = "tcp://";
  11. $urlinfo['port'] = "80";
  12. }
  13. $fp = @fsockopen($transports.$urlinfo['host'], $urlinfo['port'], $errno, $errstr, $time_out);
  14. if (!$fp) {
  15. die("ERROR: $errno - $errstr
    n");
  16. }else{
  17. fputs($fp, "POST ".$urlinfo['path']." HTTP/1.1rn");
  18. fputs($fp, "Host: ".$urlinfo['host']."rn");
  19. fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
  20. fputs($fp, "Content-length: ".strlen($urlinfo['query'])."rn");
  21. fputs($fp, "Connection: closernrn");
  22. fputs($fp, $urlinfo['query']."rnrn");
  23. while(!feof($fp)) {
  24. $info[]=@fgets($fp, 1024);
  25. }
  26. fclose($fp);
  27. $info = implode(",", $info);
  28. var_dump($info);
  29. }
  30. }
复制代码


Statement:
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
Previous article:Personal file backupNext article:Personal file backup