What potential security risks are associated with displaying a user's IP address on a website using PHP?

Displaying a user's IP address on a website using PHP can pose a potential security risk as it exposes sensitive information about the user's location and device. To mitigate this risk, it is recommended to store the IP address securely on the server side and only display it to authorized users with proper access controls.

<?php
// Store the user's IP address securely on the server side
$user_ip = $_SERVER['REMOTE_ADDR'];

// Display the IP address only to authorized users
if($_SESSION['user_role'] == 'admin'){
    echo "User's IP address: " . $user_ip;
}
?>