访问跟踪有时不起作用

时间:2017-11-10 07:31:56

标签: php

$address = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if (strpos($address, 'localhost') == false) {
    $stack = explode('/', $_SERVER["REQUEST_URI"]);
    $page = array_pop($stack);

    $ip = $_SERVER['REMOTE_ADDR'];
    $query = @unserialize(file_get_contents('http://ip-api.com/php/'.$ip));
    $country = $query['country'];
    $city = $query['city'];
    $isp = $query['isp'];

    if (!$ip == 'IPADDRESS') {
        try {
            $sql = "insert into stat (country, city, isp, ip, page) values (:acountry, :acity, :aisp, :aip, :apage)";
            $st = $db->prepare($sql);
            $st->execute([
                ":acountry" => $country,
                ":acity" => $city,
                ":aisp" => $isp,
                ":aip" => $ip,
                ":apage" => $page
            ]);
        }
        catch(PDOException $e) {
            echo $e->getMessage();
        }
    }
}

有时这不起作用。数据未插入数据库。

原因可能是移动访问或可能是Chrome隐身模式还是......什么?

0 个答案:

没有答案