What is the recommended way to retrieve the IP address of a user in PHP?

To retrieve the IP address of a user in PHP, you can use the $_SERVER['REMOTE_ADDR'] variable. This variable contains the IP address of the user who is accessing your website. It is important to note that this method may not always return the true IP address of the user if they are behind a proxy or using a VPN.

// Retrieve the IP address of the user
$user_ip = $_SERVER['REMOTE_ADDR'];

// Output the IP address
echo "User IP Address: " . $user_ip;