简体   繁体   English

file_get_contents($ URL)返回“权限被拒绝”错误

[英]file_get_contents ($URL) returns “Permission Denied” error

I lifted the following PHP code to enable me find users' location information, which will enable me execute some levels of restrictions. 我解除了以下PHP代码,使我能够找到用户的位置信息,这将使我能够执行某些级别的限制。

However, the code works well on my localhost server. 但是,该代码在我的本地主机服务器上运行良好。 But when I upload the same php files to my remote web server, it returns an error thus: 但是,当我将相同的php文件上传到远程Web服务器时,它将返回错误,因此:

Warning: file_get_contents( http://api.codehelper.io/ips/?php&ip=192.168.1.1 ): failed to open stream: Permission denied in /home/www/xyberinternational.com/lotto247.biz/visitorlocation/userip/ip.codehelper.io.php on line 41. 警告:file_get_contents( http://api.codehelper.io/ips/?php&ip=192.168.1.1 ):无法打开流:/home/www/xyberinternational.com/lotto247.biz/visitorlocation/userip/ip中的权限被拒绝第41行的.codehelper.io.php。

I have included the following files and their codes below. 我在下面包括了以下文件及其代码。 How can I fix this error? 如何解决此错误?

Index.php file Index.php文件

<?php
require_once("userip/ip.codehelper.io.php");
require_once("userip/php_fast_cache.php");
$_ip = new ip_codehelper();

$real_client_ip_address = $_ip->getRealIP();
$visitor_location       = $_ip->getLocation($real_client_ip_address);

$guest_ip   = $visitor_location['IP'];
$guest_country = $visitor_location['CountryName'];
$guest_city  = $visitor_location['CityName'];
$guest_state = $visitor_location['RegionName'];

echo "IP Address: ". $guest_ip. "<br/>";
echo "Country: ". $guest_country. "<br/>";
echo "State: ". $guest_state. "<br/>";
echo "City: ". $guest_city. "<br/>";


$ip             = $visitor_location['IP'];
$Continent_Code     = $visitor_location['ContinentCode'];
$Continent_Name     = $visitor_location['ContinentName'];
$Country_Code2      = $visitor_location['CountryCode2'];
$Country_Code3      = $visitor_location['CountryCode3'];
$Country        = $visitor_location['Country'];
$Country_Name       = $visitor_location['CountryName'];
$State_Name         = $visitor_location['RegionName'];
$City_Name      = $visitor_location['CityName'];
$City_Latitude      = $visitor_location['CityLatitude'];
$City_Longitude     = $visitor_location['CityLongitude'];
$Country_Latitude   = $visitor_location['CountryLatitude'];
$Country_Longitude  = $visitor_location['CountryLongitude'];
$Country_Longitude  = $visitor_location['CountryLongitude'];
$LocalTimeZone      = $visitor_location['LocalTimeZone'];
$Calling_Code       = $visitor_location['CallingCode'];
$Population     = $visitor_location['Population'];
$Area_SqKm      = $visitor_location['AreaSqKm'];
$Capital        = $visitor_location['Capital'];
$Electrical     = $visitor_location['Electrical'];
$Languages      = $visitor_location['Languages'];
$Currency       = $visitor_location['Currency'];
$Flag           = $visitor_location['Currency'];
?>

ip.coderhelper.io.php file ip.coderhelper.io.php文件

<?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;
    }
}

Meanwhile, the fastcatch.php is quite large. 同时,fastcatch.php很大。

This is your issue right here: 这是您遇到的问题:

    $url = "http://api.codehelper.io/ips/?callback=codehelper_ip_callback&ip=".$ip;
    $data = file_get_contents($url);

(Near the bottom of the ip.coderhelper.io.php file) (在ip.coderhelper.io.php文件的底部附近)

This is throwing an error because the server you are trying to grab the data from is denying you access to the file. 这引发了错误,因为您尝试从中获取数据的服务器拒绝您访问该文件。 You have a couple options: 您有两种选择:

1) Talk to the codehelper.io staff and see if perhaps your server's IP is blacklisted or the general range is (Some times, depending on where you buy your server from companies black list the IP's because they are known to send out malicous attacks or requests.). 1)与codehelper.io工作人员联系,查看您的服务器IP是否被列入黑名单,或者一般范围是否被列入黑名单。要求。)。 Ask them to see if they can resolve the issue. 询问他们是否可以解决问题。

2) If that isn't a viable option, you can look at this post and the second answer has a little hacky work around. 2)如果这不是一个可行的选择,则可以看一下这篇文章 ,第二个答案有些棘手。 It is worth a shot. 值得一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM