首頁 >後端開發 >php教程 >fsockopen存取網址

fsockopen存取網址

WBOY
WBOY原創
2016-07-25 08:49:211221瀏覽
学习自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. }
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:個人檔案備份下一篇:個人檔案備份