Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 文件“获取内容($URL)返回”;“拒绝许可”;错误_Php_Location_Ip_File Get Contents_Access Denied - Fatal编程技术网

Php 文件“获取内容($URL)返回”;“拒绝许可”;错误

Php 文件“获取内容($URL)返回”;“拒绝许可”;错误,php,location,ip,file-get-contents,access-denied,Php,Location,Ip,File Get Contents,Access Denied,我提升了下面的PHP代码,使我能够找到用户的位置信息,这将使我能够执行一些级别的限制 但是,该代码在本地主机服务器上运行良好。但是,当我将相同的php文件上载到远程web服务器时,它会返回一个错误,因此: 警告: 文件获取内容(): 无法打开流:中的权限被拒绝 /home/www/xyberinternational.com/lotto247.biz/visitorlocation/userip/ip.codeheloper.io.php 第41行 我在下面包含了以下文件及其代码。如何修复此错误

我提升了下面的PHP代码,使我能够找到用户的位置信息,这将使我能够执行一些级别的限制

但是,该代码在本地主机服务器上运行良好。但是,当我将相同的php文件上载到远程web服务器时,它会返回一个错误,因此:

警告: 文件获取内容(): 无法打开流:中的权限被拒绝 /home/www/xyberinternational.com/lotto247.biz/visitorlocation/userip/ip.codeheloper.io.php 第41行

我在下面包含了以下文件及其代码。如何修复此错误

Index.php文件

ip.coderhelper.io.php文件
这是您的问题:

    $url = "http://api.codehelper.io/ips/?callback=codehelper_ip_callback&ip=".$ip;
    $data = file_get_contents($url);
(位于ip.coderhelper.io.php文件底部附近)

这会引发错误,因为您试图从中获取数据的服务器拒绝您访问该文件。您有两个选择:

1) 与codeheloper.io工作人员交谈,看看您的服务器的IP是否被列入黑名单,或者一般范围是否被列入黑名单(有时,取决于您从公司购买服务器的地点,黑名单中列出了IP,因为已知这些公司会发送恶意攻击或请求)。让他们看看是否能解决这个问题


2) 如果这不是一个可行的选择,你可以看看,第二个答案有一个小黑客的工作。值得一试。

尝试使用cUrl()代替。使用
cUrl
,因为一些(大多数)主机使用URL阻止
文件获取内容。这是一个安全问题……在我的本地主机上,我启用了curl.php.extension,它可以正常工作。但是,我在我的远程主机上也做了同样的事情,但是它仍然不能工作。你看,如果我在本地主机上运行这段代码,它就可以正常工作。即使我将$ip=127.0.1.1更改为$ip=80.44.93.12,它也可以正常工作。它列出了该ip来自的国家。但是,当我将其上传到远程服务器时,它会生成一个错误…因为无法打开流。拒绝许可。请再调查一下。谢谢。请阅读我刚才所说的,远程服务器被codehelper.io阻止。$ip变量不是决定403错误的东西,数据发送的实际位置是。
<?php
class ip_codehelper {
public function getRealIP() {
    $ipaddress = '';
    if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
        $ipaddress = $_SERVER['HTTP_CF_CONNECTING_IP'];
    } else if (isset($_SERVER['HTTP_X_REAL_IP'])) {
        $ipaddress = $_SERVER['HTTP_X_REAL_IP'];
    }
    else if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';

    return $ipaddress;
}

public function getLocation($ip="") {
    if($ip == "") {
        $ip = $this->getRealIP();
    }
    if(!class_exists("phpFastCache")) {
        die("Please required phpFastCache Class");
    }
    // you should change this to cURL()
    $data = phpFastCache::get("codehelper_ip_".md5($ip));
    // caching 1 week


   if($data == null) {
        $url = "http://api.codehelper.io/ips/?callback=codehelper_ip_callback&ip=".$ip;
        $json = file_get_contents($url);
        $data = json_decode($json,true);
        phpFastCache::set("codehelper_ip_".md5($ip),$data,3600*24*7);
    }

    return $data;
}

public function SSLForwardJS() {
    $ip = $this->getRealIP();
    if(!class_exists("phpFastCache")) {
        die("Please required phpFastCache Class");
    }

    // you should change this to cURL()
    $data = phpFastCache::get("codehelper_ip_ssl".md5($ip));
    // caching 1 week
    if($data == null) {
        $url = "http://api.codehelper.io/ips/?callback=codehelper_ip_callback&ip=".$ip;
        $data = file_get_contents($url);

            phpFastCache::set("codehelper_ip_ssl".md5($ip),$data,3600*24*7);
        }
        return $data;
    }
}
    $url = "http://api.codehelper.io/ips/?callback=codehelper_ip_callback&ip=".$ip;
    $data = file_get_contents($url);