Home > Backend Development > PHP Tutorial > Share PHP function usage gadgets (with code examples)

Share PHP function usage gadgets (with code examples)

藏色散人
Release: 2023-04-11 09:52:01
forward
3251 people have browsed it

本篇文章给大家带来了关于PHP的相关知识,其中主要介绍了PHP怎么检测IP相关信息的,以及PHP如何获取HTTP、vue包等,感兴趣的朋友,下面一起来看一下吧,希望对大家有帮助。

Share PHP function usage gadgets (with code examples)

  • PHP检测IP是否内网地址、保留地址

/**
 * @param string $ip 被检测的IP
 * @return bool 是否内网或者保留IP
 */
public function isInternalIp($ip)
{
    $ip = ip2long($ip);
    if (!$ip) {
        //非法IP,直接算true吧
        return true;
    }
    $net_a = ip2long('10.255.255.255') >> 24; //A类网预留ip的网络地
    $net_b = ip2long('172.31.255.255') >> 20; //B类网预留ip的网络地址
    $net_c = ip2long('192.168.255.255') >> 16; //C类网预留ip的网络地址
    $net_local127 = ip2long('127.255.255.255') >> 24; //127保留地址
    $net_local169 = ip2long('169.254.255.255') >> 16; //169保留地址
    return $ip >> 24 === $net_a || $ip >> 20 === $net_b || $ip >> 16 === $net_c || $net_local127 === $ip >> 24 || $net_local169 === $ip >> 16;
}
Copy after login

这个是我网上找来的,具体地址我忘了,然后自己加了保留地址的检测

  • PHP获取HTTP包流量整个HTTP请求包流量

    public function http()
    {
        $row = $_SERVER['REQUEST_URI'] . "\r\r";
        $header = getallheaders();
        foreach ($header as $k => $v) {
            $row .= $k . ': ' . $v . "\r";
        }
        $row .= "\r\r" . file_get_contents("php://input");
        return $row;
    }
Copy after login
  • vue差量更新包-PHP处理

public function test()
{
    $config = json_decode(file_get_contents('vueconfig.json'), true); //配置目录,初次使用要先建立配置
    $path = 'D:\\web\\project\\vue\\dist\\static\\'; // 打包的静态地址
    foreach ($config as  $dir => $type) {
        foreach (scandir($path . $dir) as $fkey => $fva) {
            if ($fva == '.' || $fva == '..') {
                continue;
            } else {
                if (in_array($fva, $type)) {
                    //没有更新就删除该文件
                    unlink($path . $dir . '\\' . $fva);
                } else {
                    echo &#39;新增文件:&#39; . $path . $dir . &#39;\\&#39; . $fva . "<br>";
                    //有更新就把新文件加入到配置表里记录
                    $config[$dir][$fkey] = $fva;
                }
            }
        }
    }
    //更新配置表
    file_put_contents(&#39;vueconfig.json&#39;, json_encode($config));
}
Copy after login

直接运行即可删除没有改变的文件,保留更新的文件,实现差量更新

推荐学习:《PHP视频教程

The above is the detailed content of Share PHP function usage gadgets (with code examples). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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