php获取本地IP

<?php
function get_client_ip() {
    if ($_SERVER['REMOTE_ADDR']) {
        $cip = $_SERVER['REMOTE_ADDR'];
    } elseif (getenv("REMOTE_ADDR")) {
        $cip = getenv("REMOTE_ADDR");
    } elseif (getenv("HTTP_CLIENT_IP")) {
        $cip = getenv("HTTP_CLIENT_IP");
    } else {
        $cip = "unknown";
    }
    return $cip;
}
echo "IP:" . get_client_ip();
?>

 

posted on 2014-12-24 13:36  一条大鱼  阅读(2705)  评论(0编辑  收藏  举报