N
N
newaitix2022-03-24 20:52:23
PHP
newaitix, 2022-03-24 20:52:23

How to find the user's ip?

There was always a standard code

function get_ip(){
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
        $ip=$_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

I recently started using WARP. In theory, my ip should change at the same time. Looked at different services. Some of them determine my real ip without problems, and some determine ip cloudflare. And this standard script also determines ip cloudflare and how to determine the real ip?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
galaxy, 2022-03-24
@newaitix

The original visitor IP address appears in an appended HTTP header called CF-Connecting-IP . By following our webserver instructions, you can log the original visitor IP address at your origin server.

https://support.cloudflare.com/hc/en-us/articles/2...
In PHP, look for this header here:
$_SERVER["HTTP_CF_CONNECTING_IP"]

F
FanatPHP, 2022-03-24
@FanatPHP

There has always been a standard shit code that lamers all over the world diligently rewrite from each other, not understanding its meaning. Only
$ip=$_SERVER['REMOTE_ADDR']; should be left of it;
and the rest of the heresy in the trash.
Read here: phpfaq.ru/tech/ip

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question