How do I get the IP and port of a client with PHP?
I tried the script below but it only gives me the IP address.
解决方案
Port is defined in http server (Apache or other and mostly it is 80 or 443)
I am sure that :
REMOTE_ADDR'
The IP address from which the user is viewing the current page.
But if your server is behind NAT:
If you are serving from behind a proxy server, you will almost
certainly save time by looking at what these $_SERVER variables do on
your machine behind the proxy.
$_SERVER['HTTP_X_FORWARDED_FOR'] in place of $_SERVER['REMOTE_ADDR']
$_SERVER['HTTP_X_FORWARDED_HOST'] and
$_SERVER['HTTP_X_FORWARDED_SERVER'] in place of
$_SERVER['SERVER_NAME']
:-)