当前位置:Gxlcms > PHP教程 > fsockopen访问网址

fsockopen访问网址

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

学习自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.1\r\n");
  18. fputs($fp, "Host: ".$urlinfo['host']."\r\n");
  19. fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
  20. fputs($fp, "Content-length: ".strlen($urlinfo['query'])."\r\n");
  21. fputs($fp, "Connection: close\r\n\r\n");
  22. fputs($fp, $urlinfo['query']."\r\n\r\n");
  23. while(!feof($fp)) {
  24. $info[]=@fgets($fp, 1024);
  25. }
  26. fclose($fp);
  27. $info = implode(",", $info);
  28. var_dump($info);
  29. }
  30. }

人气教程排行