The reason why you are getting a different IP address on Safari iOS compared to Windows 10 is likely due to the way that the network is configured on the iOS device.
It’s possible that the IP address you are seeing on iOS is the IP address of a proxy or intermediate server that is forwarding the request on to your server. This is why you are seeing a different IP address than your actual IP address.
In your PHP function, you are checking several different server variables to try and determine the client’s IP address. However, the order in which these variables are checked may not be optimal for all scenarios.
Here’s a modified version of your function that checks the server variables in a more optimal order, based on common proxy configurations:
Even that might not might be a fix as the IP (on iOS) might be getting another server’s IP before it gets the actual IP. I’m not a hacker, but I would suspect that is how people with hacking skills and VPN masks the real IPs.