get client IP in socket programming in PHP

后端 未结 2 1277
臣服心动
臣服心动 2021-01-21 01:02

I\'m using PHP to write a using socket library application. How could I get the IP of the client? THanks for any help

相关标签:
2条回答
  • 2021-01-21 01:26

    Use socket_getpeername

    0 讨论(0)
  • 2021-01-21 01:37
    <?php
    if ($_SERVER['HTTP_CLIENT_IP'])
        $visitorIP = $_SERVER['HTTP_CLIENT_IP'];
    elseif ($_SERVER['HTTP_X_FORWARDED'])
        $visitorIP = $_SERVER['HTTP_X_FORWARDED'];
    elseif ($_SERVER['HTTP_X_FORWARDED_FOR'])
        $visitorIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else
        $visitorIP = $_SERVER['REMOTE_ADDR'];
    
    ?>
    

    For more/discussion - getting visitor's real IP address

    0 讨论(0)
提交回复
热议问题