php判断访问者IP弹出不同的内容

fugui 2016-8-22 1079

用户要求根据不同省份的访客自动弹出对应省份的客服。
这样方便客服跟客户的沟通。
下面代码简单修改就可以使用
[indent]
<div align="left"><?php
function getIpAddress(){
$ipContent = file_get_contents(“<a href="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" target="_blank">http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js</a>”);
$jsonData = explode(“=”,$ipContent);
$jsonAddress = substr($jsonData[1], 0, -1);
return $jsonAddress;
}
$ip_info=json_decode(getIpAddress());</div><div align="left">$ip_info->province;</div><div align="left">?>
<script type=”text/javascript” language=”javascript”>
var city='<?php echo $ip_info->province;?>’; //根据IP地址所有城市跳转到指定页面</div><div align="left">if(city.indexOf(“山东”)>=0){
window.location.href=”<a href="http://shanghai.demo.com/" target="_blank">http://shanghai.demo.com/</a>”; }
if(city.indexOf(“广东”)>=0){
window.location.href=”<a href="http://shanghai.demo.com/" target="_blank">http://shanghai.demo.com/</a>”; }
if(city.indexOf(“上海”)>=0){
window.location.href=”<a href="http://shanghai.demo.com/" target="_blank">http://shanghai.demo.com/</a>”; }
</script></div>

[/indent]
然后呢
我直接弹出QQ客服
[indent]
<div align="left"><?php
function getIpAddress(){
$ipContent = file_get_contents(“<a href="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js" target="_blank">http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js</a>”);
$jsonData = explode(“=”,$ipContent);
$jsonAddress = substr($jsonData[1], 0, -1);
return $jsonAddress;
}
$ip_info=json_decode(getIpAddress());</div><div align="left">$ip_info->province;</div><div align="left">if ($ip_info->province==”上海”)
{
echo “<a title=\”在线咨询\” href=\”<a href="http://wpa.qq.com/msgrd?v=3&uin=998888&site=qq&menu=yes" target="_blank">http://wpa.qq.com/msgrd?v=3&uin=998888&site=qq&menu=yes</a>\” target=\”_parent\”> “;}</div><div align="left">else {
echo “<a title=\”在线咨询\” href=\”<a href="http://wpa.qq.com/msgrd?v=3&uin=9999&site=qq&menu=yes" target="_blank">http://wpa.qq.com/msgrd?v=3&uin=9999&site=qq&menu=yes</a>\” target=\”_parent\”> “; }
?></div>

[/indent]
最新回复 (0)
返回
发新帖