Home Backend Development PHP Tutorial 屏蔽国内IP,访问需要进行身份验证解决思路

屏蔽国内IP,访问需要进行身份验证解决思路

Jun 13, 2016 pm 01:33 PM
empty location quot tmp

屏蔽国内IP,访问需要进行身份验证
有一外贸网站想屏蔽国内IP,但我们自己需要管理和允许特定的国内用户访问所以要进行身份验证,请问这样的功能要怎样实现呢?第一次发帖,请大家多关注!谢谢!

------解决方案--------------------
可以做个页面,在用户访问时,
1.获取用户的IP
2.然后到开放的IP接口去查询用户的地理位置(例如新浪、网易、ip138,都有开放的ip查询接口)
3.有了用户的地理位置,再决定是屏蔽之,还是验证之
------解决方案--------------------

PHP code

function sina($ip)
{
    $php_runtime = microtime(TRUE);
    $str = file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=".$ip);
    $tmp = explode("    ",$str);
    (isset($tmp[4]) && !empty($tmp[4])) ? $location['country'] = $tmp[4] : $location['country'] = null;
    (isset($tmp[5]) && !empty($tmp[5])) ? $location['city'] = $tmp[5] : $location['city'] = null;
    (empty($tmp[6]) || !preg_match("/电/",$str) || !preg_match("/通/",$str)) ? $location['sp'] = $tmp[7] : $location['sp'] = $tmp[6];

    $location['time'] = microtime(TRUE) - $php_runtime;
    if(!empty($location))
        return $location;
    else
        return false;
}
<br><font color="#e78608">------解决方案--------------------</font><br>通过用户来访的IP地址可以算出该IP属于哪个子网,如110.80.0.0/13<br>将全中国可划分的子网存在一个数组中,判断是否在这个数组中就行了。<br><br>不需要再去其他接口查询地址,然后根据地址或运营商的名字来判断,反而麻烦。<br>PS:这个数组不大,不到800条。<br><br>换算的方法请看此页面:http://url.cn/0TCFrY  内附全中国可划分子网的excel下载<br><br>
<br><font color="#e78608">------解决方案--------------------</font><br>ftp://ftp.apnic.net/public/apnic/stats/apnic/delegated-apnic-latest<br><br>apnic|CN|ipv4|180.212.0.0|131072|20091001|allocated<br><br>这就是国内的. 分析提取. 然后过滤IP就可以了 <div class="clear">
                 
              
              
        
            </div>
Copy after login
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The cleaning principle of /tmp/ folder in Linux system and the role of tmp file The cleaning principle of /tmp/ folder in Linux system and the role of tmp file Dec 21, 2023 pm 05:36 PM

Most of the .tmp files are files left behind due to abnormal shutdown or crash. These temporary scratch disks have no use after you restart the computer, so you can safely delete them. When you use the Windows operating system, you may often find some files with the suffix TMP in the root directory of the C drive, and you will also find a TEMP directory in the Windows directory. TMP files are temporary files generated by various software or systems. , also known as junk files. Temporary files generated by Windows are essentially the same as virtual memory, except that temporary files are more targeted than virtual memory and only serve a certain program. And its specificity has caused many novices to be intimidated by it and not delete it.

What does tmp mean in linux What does tmp mean in linux Mar 10, 2023 am 09:26 AM

In Linux, tmp refers to a folder that stores temporary files. This folder contains temporary files created by the system and users; the default time limit of the tmp folder is 30 days. Files under tmp that are not accessed for 30 days will be automatically deleted by the system. of.

How to access and clean junk files in /tmp directory in CentOS 7? How to access and clean junk files in /tmp directory in CentOS 7? Dec 27, 2023 pm 09:10 PM

There is a lot of garbage in the tmp directory in the centos7 system. If you want to clear the garbage, how should you do it? Let’s take a look at the detailed tutorial below. To view the list of files in the tmp file directory, execute the command cdtmp/ to switch to the current file directory of tmp, and execute the ll command to view the list of files in the current directory. As shown below. Use the rm command to delete files. It should be noted that the rm command deletes files from the system forever. Therefore, it is recommended that when using the rm command, it is best to give a prompt before deleting the file. Use the command rm-i file name, wait for the user to confirm deletion (y) or skip deletion (n), and the system will perform corresponding operations. As shown below.

Analysis of location configuration examples in Nginx server Analysis of location configuration examples in Nginx server May 24, 2023 pm 02:05 PM

First, let me briefly introduce the types of location and matching rules, using the example of nginxwiki as an example: location=/{#matchesthequery/only.[configurationa]}location/{#matchesanyquery,sinceallqueriesbeginwith/,butregular#expressionsandanylongerconventionalblockswillbe#matchedfirst.[ configurationb]}location^~/im

What file is TmP? What file is TmP? Dec 25, 2023 pm 03:39 PM

The "tmp" file is a temporary file, usually generated by the operating system or program during operation, and is used to store temporary data or intermediate results when the program is running. These files are mainly used to help the program execute smoothly, but they are usually automatically deleted after the program is executed. tmp files can usually be found in the root directory of the C drive on Windows systems. However, tmp files are associated with a specific application or system, so their specific content and purpose may vary from application to application.

How to intercept uri in nginx location How to intercept uri in nginx location May 18, 2023 pm 12:07 PM

Note: The root and aliasroot instructions in location only set the search root to the directory set by root, that is, the uri will not be truncated. Instead, the original uri will be used to jump to the directory to find the file. The aias instruction will truncate the matching uri, and then Use the path set by alias plus the remaining uri as a sub-path to find the uri of proxy_pass in location. If the url of proxy_pass does not have uri, if the tail is "/", the matching uri will be truncated. If the tail is not "/", then Will not truncate the matching uri if the proxy_pass url contains uri

PHP determines whether a specified key exists in an array PHP determines whether a specified key exists in an array Mar 21, 2024 pm 09:21 PM

This article will explain in detail how PHP determines whether a specified key exists in an array. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP determines whether a specified key exists in an array: In PHP, there are many ways to determine whether a specified key exists in an array: 1. Use the isset() function: isset($array[&quot;key&quot;]) This function returns a Boolean value, true if the specified key exists, false otherwise. 2. Use array_key_exists() function: array_key_exists(&quot;key&quot;,$arr

What file is tmp What file is tmp Feb 22, 2023 pm 02:35 PM

tmp is a temporary file generated by various software or systems, which is often called junk file. Usually, programs that create temporary files delete them when they are finished, but sometimes these files are retained. There may be many reasons why temporary files are retained: the program may be interrupted before completing the installation, or crash during restart; these files generally have little use value, and we can delete them directly.

See all articles