ecshop头部添加所在城市
首先,在/includes/lib_main.php中,找到代码:function assign_template($ctype = '', $catlist = array()) ,在方法中添加代码:
$smarty->assign('location_city', get_location_city()); 并在文件末尾添加如下方法:
function get_location_city(){
$loc_ip=real_ip();
$loc_ip138Addr = "http://whois.pconline.com.cn/ipJson.jsp?callback=testJson&ip=".$loc_ip; //一个桶过ip获取当前所在地区的接口
$loc_contents = file_get_contents($loc_ip138Addr);
$loc_intStart = strpos($loc_contents,"new Array(")+10;
$loc_intEnd = strpos($loc_contents,");");
$loc_Info = substr($loc_contents,$loc_intStart,$loc_intEnd-$loc_intStart);
$loc_Info = str_replace("\"","",$loc_Info);
$loc_place = explode(",",$loc_Info);
list($loc_IP,$loc_Country,$loc_Province,$loc_City,$loc_Net) = $loc_place;
$loc_num=strpos($loc_City,":");
$loc_area=substr($loc_City,$loc_num+1);
$loc_area = ecs_iconv('GBK', 'UTF8', $loc_area);
return $loc_area;
}
然后在/themes/default/library/page_header.lbi中,随便找个地方写入代码:{$location_city},便可在头部显示当前所在城市,显示位置可在css中调试。