search

Home  >  Q&A  >  body text

javascript - 怎么做一个网站的被访问记录数据

PHP中文网PHP中文网2785 days ago497

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 16:35:12

    function getip(){
        static $ip = '';
        $ip = $_SERVER['REMOTE_ADDR'];
        if (isset( $_SERVER['HTTP_CDN_SRC_IP'] )) {
            $ip = $_SERVER['HTTP_CDN_SRC_IP'];
        } elseif (isset( $_SERVER['HTTP_CLIENT_IP'] ) && preg_match('/^([0-9]{1,3}\.){3}[0-9]{1,3}$/', $_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches)) {
            foreach ($matches[0] AS $xip) {
                if (!preg_match('#^(10|172\.16|192\.168)\.#', $xip)) {
                    $ip = $xip;
                    break;
                }
            }
        }
        return $ip;
    }

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 16:35:12

    Why not use a third party, like Baidu Statistics, apply for settlement, get the code, put it into your code, and you can see it through the background

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 16:35:12

    You can add a filter to the front end to get the IP from the requset header, or perform some statistical operations, similar to node (express)

    const ip = req.headers['x-forwarded-for'] ||
                    req.connection.remoteAddress ||
                    req.socket.remoteAddress;
     
    // 一些统计的代码
    ...
    
    // 再往下传递
    next();

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 16:35:12

    Add a table directly to your database

    reply
    0
  • Cancelreply