destoon6.0多城市或开设分站开发教程

第一步 -> 在 extend.func.php 内加入以下函数

     function get_ip2city($ip){
        global $db;
        $city = ip2area($ip);
        if(is_array($all_city = cache_read('allcity.php'))){
                foreach($all_city as $k => $v){
                        $v['name'] = str_replace(array("市","区"," "),array("","",""),$v['name']);
                        if(@strstr($city,$v['name'])){
                                return $v;
                        }
                }
        }

第二步 -> api\city.php 的 $lists = array(); 上面添加 以下代码
$xxxx = get_ip2city($DT_IP);
看到好多站有类似 猜您可能在西安, 点击进入西安站>>
如图:

所有搞了类似一个小功能,希望对需要的哥们AND妹妹有用。

第一步 -> 在 extend.func.php 内加入以下函数
function get_ip2city($ip){
global $db;
$city = ip2area($ip);
if(is_array($all_city = cache_read('allcity.php'))){
foreach($all_city as $k => $v){
$v['name'] = str_replace(array("市","区"," "),array("","",""),$v['name']);br/>if(@strstr($city,$v['name'])){
return $v;
}
}
}

第二步 -> api\city.php 的 $lists = array(); 上面添加 以下代码

$xxxx = get_ip2city($DT_IP);

以下我临时用的是一下判断仅供参考

// $DT_IP = '113.132.197.181';  //本地临时测试的IP,实际使用时删除本行代码。

if(get_ip2city($DT_IP)){
        $xxxx = get_ip2city($DT_IP);
}else{
        $xxxx['name'] = $L['allcity'];
        $xxxx['domain'] = $xxxx['areaid'] = $xxxx['style'] = '';
}

第三步 -> 在模版文件 city.htm 文件中 想添加的部分添加模版代码
<!--[ $xxxx 变量自行取名 我这里就用 xxxx 代替了 ]-->
<a href="{if $xxxx[domain]}{$xxxx[domain]}{else}javascript:gocity('areaid={$xxxx[areaid]}');{/if}">
点击进入{set_style($xxxx[name], $xxxx[style])}站
</a>


<!--[ $xxxx 变量自行取名 我这里就用 xxxx 代替了 ]-->
<!--[ {if $xxxx}代码段{/if} 判断当前城市是否开通了分站的,高手可以无视模版代码 ]-->
{if $xxxx}
<a href="{if $xxxx[domain]}{$xxxx[domain]}{else}javascript:gocity('areaid={$xxxx[areaid]}');{/if}">
点击进入{set_style($xxxx[name], $xxxx[style])}站
</a>
{/if}

转载于:https://blog.51cto.com/11024720/2082625

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值