- PHP

How to get IP address in PHP code

Use the $_SERVER[‘REMOTE_ADDR’].

<?php

$ip = $_SERVER['REMOTE_ADDR'];

?>

Example:

Echo the client IP address in PHP.

<?php

echo 'IP address: ' . $_SERVER['REMOTE_ADDR'];

?>