php - 根据使用 PHP 输入的用户所在国家/地区隐藏 div
问题描述
我得到了以这种方式进入的用户的ip地址。这些都没问题。
function getCountryData() {
return unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip=' . get_ip()));;
}
function getCountry() {
$languages = [
'TR' => 'tr_TR',
'EN' => 'en_US'
];
$response = getCountryData();
return array_key_exists($response['geoplugin_countryCode'], $languages) ? $languages[$response['geoplugin_countryCode']] : 'en_US';
}
这是 HTML 端的正常部分。
<p class="d-none d-sm-inline-block"><span><a href="tel:000000">000000</a></span></p>
如果输入 TR 的用户正在输入,我想隐藏这部分。我在this中写了这样的东西,我哪里出错了或者我应该怎么做?
<p class="d-none d-sm-inline-block" style="<?php if ($response['geoplugin_countryCode']) {echo 'display: none!important;';} else {echo 'display: inline-block!important;';} ?>"><span><a href="tel:000000">000000</a></span></p>
解决方案
您需要将 $response['geoplugin_countryCode'] 与 'TR' 之类的进行比较
... if ($response['geoplugin_countryCode']==='TR') {echo 'display: none!important;';} else...
推荐阅读
- sql - 在 where 子句中将字段声明为 NULL 时出错
- asp.net - 如何重定向 UI 应用程序以拒绝访问 .net 核心中的每种类型的请求
- php - 如何删除二维数组中的最后一个元素?
- sql - SQL查询检查是否存在多个条目
- c# - 无法使用实体框架连接到 C# asp mvc 应用程序中的 Sql 数据库,但相同的代码适用于 Winform 应用程序
- javascript - JavaScript 中的 ADODB.Stream - 以(正则表达式或 for 循环)开头的跳过行
- sql - 连接两个查询缺失值
- python - SLURM 批处理脚本不执行 Python 脚本,不返回错误消息并且不停止运行
- php - 在 woocommerce 管理列表状态和用户方面显示订单
- javascript - 移动js导航栏问题