开发者

Can we track clients ip address with php or javascript

开发者 https://www.devze.com 2023-03-28 12:17 出处:网络
I don\'t trust any analytics or statcounter ty开发者_C百科pe websites I want to track my visitors by my own coding

I don't trust any analytics or statcounter ty开发者_C百科pe websites I want to track my visitors by my own coding

can we track it by php or javascript if yes then how


You can use $_SERVER["REMOTE_ADDR"] to get the visitor's ip address. See http://www.php.net/manual/en/reserved.variables.server.php.


See $_SERVER['REMOTE_ADDR'] but given relative ease of use of HTTP proxies, you can't really trust it either.


can we track it by php or javascript if yes then how

Piwik is an excellent locally-hosted, PHP-driven analytics suite.

I have set it up on almost a dozen client web sites, with very good results.


You may want to use your webserver's logs, then, and generate reports with something like AWstats.


You can use $_SERVER to get the client's IP address. Based on it, you can roll out your own solution.

Alternatively, you can parse your visitor logs (apache logs for example).

However, tracking visitors is not a trivial task. Eventually, you will be looking at tracking repeat visitors, unique visitors, their demographic, their machine configuration and what not. Rolling out your own solution may just be re-inventing the wheel.


I think you cannot get it with javascript on client side. You have to execute ajax call on server and return IP from where request came to server.

You can check How to get client's IP address using javascript only?


I know you could use a PHP function like this:

function getRealIpAddr(){
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    //check if ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    //to check if ip is passed from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
        $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }

But.., take not that obviously if a visitor is using an anonymizing service, you can't grab any IP and never you can be 100% sure about real IP in any case.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号