PHP file_get_contents函数无法使用Cloudflare(Web服务器代理) [英] PHP file_get_contents function not working using Cloudflare (proxy for webserver)

查看:77
本文介绍了PHP file_get_contents函数无法使用Cloudflare(Web服务器代理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Cloudflare已有几个月了,当我使用Cloudflare时,我的支付系统无法100%正常工作.检查脚本不起作用.没有Cloudflare,一切都会很好.

I have been using Cloudflare for a few months now, and when I'm using Cloudflare, my payment system is not working 100%. The check script doesn't work. Without Cloudflare, everything works just fine.

我得到的错误是:

PHP警告:file_get_contents():php_network_getaddresses:getaddrinfo失败:这通常是主机名解析期间的临时错误,表示本地服务器未收到权威服务器的响应.在第2行的C:\ inetpub \ wwwroot \ check.php中

PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in C:\inetpub\wwwroot\check.php on line 2

PHP警告:file_get_contents( https://www.eurobellen.nl/bel/check.php?userid=name&ip=ip&ebpin= ):无法打开流:php_network_getaddresses:getaddrinfo失败:这通常是主机名解析期间的临时错误,表示本地服务器未收到来自权威服务器的响应.在第2行的C:\ inetpub \ wwwroot \ check.php中

PHP Warning: file_get_contents(https://www.eurobellen.nl/bel/check.php?userid=name&ip=ip&ebpin=): failed to open stream: php_network_getaddresses: getaddrinfo failed: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server. in C:\inetpub\wwwroot\check.php on line 2

第2行是:

$ebcheck = file_get_contents("https://www.eurobellen.nl/bel/check.php?userid=name&ip=".$ip."&ebpin=".$_GET['ebpin']);

我已经搜索了大约2个小时,我尝试了几件事,但无法解决.我希望你们知道如何解决?

I have been searching around for like 2 hours and I tried several things, but I can't fix it. I hope you guys know how to fix it?

推荐答案

您可以尝试curl进行此类任务. curl 专门用于该类型的任务.

You can try curl for this type of tasks. curl is specific for that type of tasks.

function get_contents($url, $ua = 'Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1', $referer = 'http://www.google.com/') {
  if (function_exists('curl_exec')) {
    $header[0] = "Accept-Language: en-us,en;q=0.5";
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_USERAGENT, $ua);
    curl_setopt($curl, CURLOPT_REFERER, $referer);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    $content = curl_exec($curl);
    curl_close($curl);
  }
  else { 
    $content = file_get_contents($url);
  }
  return $content;
}

以上功能检查是否安装了curl extension.如果已安装,则无论如何都会使用curl,它会使用 file_get_contents();

Above function checks if curl extension is installed or not. If installed then uses curl anyway it uses file_get_contents();

这篇关于PHP file_get_contents函数无法使用Cloudflare(Web服务器代理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆