我正在使用Ip2location插件来提取基于Ip地址的状态数据到我的帖子中。
这很容易安装插件,然后在post或页面编辑器中使用{ip:区域名}。
但是我想在标题旁边的模板头文件中打印这个信息。
这有可能吗?如果是的话,我该怎么做?
模板中的头php是这样的。
'square',
) ); ?>这是ip2location所说的在PHP中使用那里服务的方式
https://www.ip2location.com/developers/php
我不是一个全职的编码器,任何关于如何尝试的例子都会很有帮助。
手机数据上的Error
谢谢您的建议@nmr,我在其他插件上发现了很多but,所以我决定修复它们,看看它是否会使ip2location工作,但它没有。
Wifi /以太网连接:(这很好)
2018-08-31 17:39:53 Lookup by BIN database.
2018-08-31 17:39:53 Geolocation result for [66.219.198.137] found: Array
(
[ipNumber] => 1121699465
[ipVersion] => 4
[ipAddress] => 66.219.198.137
[countryName] => United States
[countryCode] => US
[cityName] => Lehi
[regionName] => Utah
)Cell电话LTE数据连接:
2018-08-31 17:40:04 Lookup by BIN database.
2018-08-31 17:40:31 Lookup by BIN database.
2018-08-31 17:40:31 Geolocation result for [127.0.0.1] found: Array
(
[ipNumber] => 2130706433
[ipVersion] => 4
[ipAddress] => 127.0.0.1
[countryName] => -
[countryCode] => -
[cityName] => -
[regionName] => -
)发布于 2018-08-24 07:26:00
我假设你在使用“件2定位标签Wordpress插件”。
在IP2Location插件的主文件中,类实例被创建并分配给变量。
$ip2location_tags =新的IP2LocationTags();
要在主题中使用插件,只需使用全局变量$ip2location_tags。记住要确保类IP2LocationTags首先存在,并使用global关键字。
if (class_exists('IP2LocationTags')) {
global $ip2location_tags;
$location = $ip2location_tags->get_location('IP_ADDRESS');
}插件以这种方式设置IP地址(在parse_content方法中):
$ip_address = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}位置数据表中的键:
ipAddress、countryCode、countryName、regionName、cityName、纬度、经度、isp、domainName、zipCode、timeZone、netSpeed、iddCode、areaCode、weatherStationCode、weatherStationName、mcc、mnc、mobileCarrierName、高程、usageType、
在functions.php文件中添加函数:
if ( !function_exists( 'ip2loc_get_region' ) ) {
function ip2loc_get_region() {
global $ip2location_tags;
if ( !class_exists('IP2LocationTags') )
return '';
$ip_address = $_SERVER['REMOTE_ADDR'];
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$location = $ip2location_tags->get_location($ip_address);
if ( !$location )
return '';
return $location['regionName'];
}
}文件header.php:
'square',
) ); ?>https://wordpress.stackexchange.com/questions/312358
复制相似问题