setup($userip)){...}" to determine ip Just jump."/> setup($userip)){...}" to determine ip Just jump.">
Home >Backend Development >PHP Problem >How to determine ip jump in php
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.
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>
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('I am China ip'); } else { //alert('I am not China ip'); location.href="英文网站"; } }, complete:function(XMLHttpRequest,textStatus) { }, error:function() { } }); } </script> <body οnlοad="initurl()"> ... </body>
Checkip.php page code :
$userip=$_SERVER['REMOTE_ADDR']; //引用ip库的文件 把ip.zip里的全部文件放在lib目录下 include_once('/lib/iplimit.class.php'); $iplimit = new iplimit; if($iplimit->setup($userip)) { echo 1; } else { echo 2; }
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!