What is the function used in PHP to retrieve the IP address of a visitor?

To retrieve the IP address of a visitor in PHP, you can use the $_SERVER['REMOTE_ADDR'] variable. This variable contains the IP address of the client making the request to the server. By accessing this variable, you can easily retrieve the IP address and use it in your PHP script for various purposes such as logging, tracking, or customization based on the visitor's location.

// Retrieve the IP address of the visitor
$ip_address = $_SERVER['REMOTE_ADDR'];

// Output the IP address
echo "Visitor's IP Address: " . $ip_address;