get client IP in socket programming in PHP

2019-02-26 11:22发布

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条回答
一夜七次
2楼-- · 2019-02-26 11:46
Root(大扎)
3楼-- · 2019-02-26 11:47
<?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

查看更多
登录 后发表回答