[英]file_get_contents ($URL) returns “Permission Denied” error
我解除了以下PHP代碼,使我能夠找到用戶的位置信息,這將使我能夠執行某些級別的限制。
但是,該代碼在我的本地主機服務器上運行良好。 但是,當我將相同的php文件上傳到遠程Web服務器時,它將返回錯誤,因此:
警告: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。
我在下面包括了以下文件及其代碼。 如何解決此錯誤?
<?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'];
?>
<?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;
}
}
同時,fastcatch.php很大。
這是您遇到的問題:
$url = "http://api.codehelper.io/ips/?callback=codehelper_ip_callback&ip=".$ip;
$data = file_get_contents($url);
(在ip.coderhelper.io.php文件的底部附近)
這引發了錯誤,因為您嘗試從中獲取數據的服務器拒絕您訪問該文件。 您有兩種選擇:
1)與codehelper.io工作人員聯系,查看您的服務器IP是否被列入黑名單,或者一般范圍是否被列入黑名單。要求。)。 詢問他們是否可以解決問題。
2)如果這不是一個可行的選擇,則可以看一下這篇文章 ,第二個答案有些棘手。 值得一試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.