仅在具有 IP 的选定区域显示内容
Display content only in selected regions with IP
是否可以只向美国展示一个特殊的网页内容?我可以用访问者的 IP 来做吗?
您可以寻找一个 API 来翻译 locations/areas 中的 IP 地址,然后使用此类数据来过滤您的访问者。
无法读取 IP 并据此确定其位置。
示例:
https://geoipify.whoisxmlapi.com/api
https://ip2loc.com/?gclid=CjwKCAjwldHsBRAoEiwAd0JybSNyxMapSYTA-twwHjVEwBjP3TC2wGojiJ292Yx7RWm3wIn7GdAtMxoCsgoQAvD_BwE
当然可以。请像下面这样尝试:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$result = file_get_contents( "http://echoip.ir/" . $ip );
if ( $result ) {
$result_decode = json_decode( $result, true );
if ( $result_decode['ip2location']['country_short'] == "US" ) {
// Show your page
}
}
?>
是否可以只向美国展示一个特殊的网页内容?我可以用访问者的 IP 来做吗?
您可以寻找一个 API 来翻译 locations/areas 中的 IP 地址,然后使用此类数据来过滤您的访问者。
无法读取 IP 并据此确定其位置。
示例:
https://geoipify.whoisxmlapi.com/api
https://ip2loc.com/?gclid=CjwKCAjwldHsBRAoEiwAd0JybSNyxMapSYTA-twwHjVEwBjP3TC2wGojiJ292Yx7RWm3wIn7GdAtMxoCsgoQAvD_BwE
当然可以。请像下面这样尝试:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$result = file_get_contents( "http://echoip.ir/" . $ip );
if ( $result ) {
$result_decode = json_decode( $result, true );
if ( $result_decode['ip2location']['country_short'] == "US" ) {
// Show your page
}
}
?>