How can PHP scripts be adjusted to handle both IPv4 and IPv6 addresses when users switch between them?

To handle both IPv4 and IPv6 addresses when users switch between them, PHP scripts can use the `filter_var()` function with the `FILTER_VALIDATE_IP` filter. This function can validate both IPv4 and IPv6 addresses. By checking the validity of the user's input using this function, the script can handle both address types seamlessly.

$ip_address = $_SERVER['REMOTE_ADDR'];

if (filter_var($ip_address, FILTER_VALIDATE_IP)) {
    echo "Valid IP address: $ip_address";
} else {
    echo "Invalid IP address";
}