So far I’m looking into using ipify’s php api for returning an ip but every time I try it returns my website ip. I want it to show user ip instead what can I do to fix that?
Here’s the code:
<?php
$ip = file_get_contents('https://api4.ipify.org');
echo "My public IP address is: " . $ip;
?>
Edit:
I understand there is this way of doing it
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo "My public IP address is: " . $ip;
?>
but i prefer $_SERVER["HTTP_CF_CONNECTING_IP"] and doing so they dont always return 1pv4. Is there any way to make it enforce ipv4 format without modifying website settings?
This should do it, no need for the API to access the IP address of the user:
Something to note though, is that this method will get whatever the IP is, so if they are using a VPN or Proxy, you will get the IP of that service.