Many times we need the visitor’s ipaddress for validation, security, spam prevention, etc. Getting the Visitor’s ipaddress is very easy in PHP.
The simplest way to get the visitor’s/client’s ipaddress is using the
$_SERVER['REMOTE_HOST'] variables. The variable in the
$_SERVER array are created by the web server (like apache) and we can use them in PHP.
// Get the client ip address $ipaddress = $_SERVER['REMOTE_ADDR']