Home > Backend Development > PHP Problem > How to determine ip jump in php

How to determine ip jump in php

藏色散人
Release: 2023-03-06 06:10:02
Original
2555 people have browsed it

php method to determine ip jump: first put all the files in "ip.zip" in the lib directory; then pass "if($iplimit->setup($userip)){.. .}" method can be used to determine the IP jump.

How to determine ip jump in php

Recommended: "PHP Video Tutorial"

php Visit domestic and foreign IP judgment codes and implement the page Jump

I recently made a request for the company website: to determine whether the visitor has entered the Chinese website or the English website based on the IP address of the visitor.

I roughly thought about it, and there are two options:

1. Javascript determines the browser language of the visitor. If it is a Chinese system, naturally the users are all Chinese, and they will jump to the Chinese website ;

If it is a non-Chinese system, the default user is non-Chinese and will jump to the English website.

Advantages: Fast judgment and reflection.

Disadvantages: Inaccurate, it is possible that Chinese users prefer to use the English version of the system, or foreigners use the Chinese system.

Code

<script type="text/javascript" language="javascript"> 
var Browser_Agent=navigator.userAgent; 
//浏览器为ie的情况 
if(Browser_Agent.indexOf("MSIE")!=-1){ 
var a=navigator.browserLanguage; 
if(a !="zh-cn"){ 
location.href="英文网站"; 
} 
} 
//浏览器非ie的情况 
else{ 
var b=navigator.language; 
if(b!="zh-CN"){ 
location.href="英文网站"; 
} 
} 
</script>
Copy after login

2. Use the IP library to judge the visiting IP

Advantages: Accurate judgment.

Disadvantages: The response speed is not as fast as Javascript.

Need to reference a PHP IP library ip_php.zip

I reference jquery at the head of the website to make a judgment

<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script> 
<script type="text/javascript" language="javascript"> 
function initurl() { 
$.ajax({ 
type:"GET", 
url:"checkip.php", 
dataType:"html", 
data:"&time="+new Date(), 
cache: false, 
async: false, 
beforeSend:function(XMLHttpRequest) { 
}, 
success:function(msg) { 
//如果返回值为1表示访问者为中国地区的ip 
if(msg == 1){ 
//alert(&#39;I am China ip&#39;); 
} 
else { 
//alert(&#39;I am not China ip&#39;); 
location.href="英文网站"; 
} 
}, 
complete:function(XMLHttpRequest,textStatus) { 
}, 
error:function() { 
} 
}); 
} 
</script> 
<body οnlοad="initurl()"> 
... 
</body>
Copy after login

Checkip.php page code :

$userip=$_SERVER[&#39;REMOTE_ADDR&#39;]; 
//引用ip库的文件 把ip.zip里的全部文件放在lib目录下 
include_once(&#39;/lib/iplimit.class.php&#39;); 
$iplimit = new iplimit; 
if($iplimit->setup($userip)) 
{ 
echo 1; 
} 
else 
{ 
echo 2; 
}
Copy after login

Both methods can perfectly determine the visiting IP. Which one you choose depends on your specific needs.

The above is the detailed content of How to determine ip jump in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template