嗨,我的php代码看起来有点偶然。以下if($location !== "AU"){条件上周还在运行,但现在不起作用。想知道ipinfo服务是否不那么稳定?我目前在AU中,我不希望它显示。有什么帮助吗?
<?php
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
$location = $details->country;
if($location !== "AU"){
if(is_page(array('industrial-hoses', 'industrial-clamps', 'industrial-
adaptors', 'rubber-industrial-hoses', 'industrial-couplings', 'industrial-
accessories', 'industrial-hose-rubber-air', 'rubber-air-water-industrial-hose',
'rubber-chemical-acid-industrial-hose', 'rubber-food-beverage-industrial-hose',
'rubber-fuel-oil-industrial-hose', 'rubber-material-handling-industrial-hose',
'rubber-multi-purpose-industrial-hose' ,'rubber-specialty-industrial-hose',
'pvc-industrial-hoses', 'pvc-air-water-industrial-hose', 'pvc-chemical-acid-
industrial-hose', 'pvc-food-beverage-industrial-hose', 'pvc-fuel-oil-
industrial-hose', 'pvc-material-handling-industrial-hose', 'pvc-multi-purpose-
industrial-hose', 'pvc-speciality-industrial-hose', 'teflon-speciality-
industrial-hose', 'flexible-ducting-speciality-industrial-hose'))){
echo '<script src="https://website.com/f/embed.php?id=7" type="text/javascript" charset="utf-8"></script>';
}
}
?>发布于 2018-11-12 08:10:20
这似乎解决了我的问题
function getClientIP(){
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
$ipaddress = getClientIP();
function ip_details($ip) {
$json = file_get_contents("http://ipinfo.io/{$ip}/geo");
$details = json_decode($json, true);
return $details;
}
$details = ip_details($ipaddress);
if($details['country'] === "AU"){
...https://stackoverflow.com/questions/53199215
复制相似问题