How can PHP scripts be optimized to accurately display the IP address of a user accessing a website?

To accurately display the IP address of a user accessing a website, PHP scripts can be optimized by using the `$_SERVER['REMOTE_ADDR']` variable. This variable contains the IP address of the user making the request to the server. By accessing this variable, you can retrieve the user's IP address and display it on the website.

$user_ip = $_SERVER['REMOTE_ADDR'];
echo "Your IP address is: " . $user_ip;