Home >类库下载 >PHP类库 >PHP method to obtain IP

PHP method to obtain IP

高洛峰
高洛峰Original
2016-10-21 10:28:021172browse

<?php
//获取IP
function get_ip() {
        if (isset($_SERVER)) {
                if (isset($_SERVER[HTTP_X_FORWARDED_FOR])) {
                        $realip = $_SERVER[HTTP_X_FORWARDED_FOR];
                } elseif (isset($_SERVER[HTTP_CLIENT_IP])) {
                        $realip = $_SERVER[HTTP_CLIENT_IP];
                } else {
                        $realip = $_SERVER[REMOTE_ADDR];
                }
        } else {
                if (getenv("HTTP_X_FORWARDED_FOR")) {
                        $realip = getenv( "HTTP_X_FORWARDED_FOR");
                } elseif (getenv("HTTP_CLIENT_IP")) {
                        $realip = getenv("HTTP_CLIENT_IP");
                } else {
                        $realip = getenv("REMOTE_ADDR");
                }
        }
        return $realip;
}
?>


Statement:
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

Related articles

See more