# Problem to get my real ip on iOS

**URL:** <https://www.phphelp.com/t/problem-to-get-my-real-ip-on-ios/35391>\
**Category:** General PHP Help\
**Created:** [April 10, 2023, 12:57am UTC](https://www.phphelp.com/t/problem-to-get-my-real-ip-on-ios/35391 "2023-04-10T00:57:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Belinda](https://www.phphelp.com/user_avatar/www.phphelp.com/belinda/32/4330_2.png) [@Belinda](https://www.phphelp.com/u/Belinda)\
**Post date:** [April 10, 2023, 12:57am UTC](https://www.phphelp.com/t/problem-to-get-my-real-ip-on-ios/35391/1 "2023-04-10T00:57:55Z")

</div>

Hello 🙂

I have a really problem to get my real IP on **iOS**. When I’m on Safari iOS, my script return this ip :

248.17._ **.** _, but my real ip is : 91.17\*._ **.** _

On **Windows 10** i don’t have problem.

If I go to on **iOS** [http://monip.org/](http://monip.org/) he display my real Ip.

I didn’t understand…

My PHP function :

```php
<?php
function getRemoteAddr()
{
    if(getenv('HTTP_CLIENT_IP')) return getenv('HTTP_CLIENT_IP');
    elseif(getenv('HTTP_X_FORWARDED_FOR')) return getenv('HTTP_X_FORWARDED_FOR');
    elseif(getenv('HTTP_X_FORWARDED')) return getenv('HTTP_X_FORWARDED');
    elseif(getenv('HTTP_FORWARDED_FOR')) return getenv('HTTP_FORWARDED_FOR');
    elseif(getenv('HTTP_FORWARDED')) return getenv('HTTP_FORWARDED');
    elseif(getenv('REMOTE_ADDR')) return getenv('REMOTE_ADDR');
    else return null;
}

```

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [April 10, 2023, 11:45am UTC](https://www.phphelp.com/t/problem-to-get-my-real-ip-on-ios/35391/2 "2023-04-10T11:45:27Z")

</div>

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:

```auto
function getRemoteAddr()
{
    $remoteAddr = null;
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ipAddresses = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
        $remoteAddr = trim(end($ipAddresses));
    } elseif(isset($_SERVER['HTTP_CLIENT_IP'])) {
        $remoteAddr = $_SERVER['HTTP_CLIENT_IP'];
    } else {
        $remoteAddr = $_SERVER['REMOTE_ADDR'];
    }
    return $remoteAddr;
}

```

---

<div class="post-metadata">

**Author:** ![Belinda](https://www.phphelp.com/user_avatar/www.phphelp.com/belinda/32/4330_2.png) [@Belinda](https://www.phphelp.com/u/Belinda)\
**Post date:** [April 11, 2023, 1:58am UTC](https://www.phphelp.com/t/problem-to-get-my-real-ip-on-ios/35391/3 "2023-04-11T01:58:46Z")

</div>

> [@Strider64](#):
>
> ```auto
> function getRemoteAddr()
> {
> $remoteAddr = null;
> if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
> $ipAddresses = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
> $remoteAddr = trim(end($ipAddresses));
> } elseif(isset($_SERVER['HTTP_CLIENT_IP'])) {
> $remoteAddr = $_SERVER['HTTP_CLIENT_IP'];
> } else {
> $remoteAddr = $_SERVER['REMOTE_ADDR'];
> }
> return $remoteAddr;
> }
> 
> ```

Yes, but why is it that on all sites they show the correct IP (on iOS), but I don’t.

---

<div class="post-metadata">

**Author:** ![Strider64](https://www.phphelp.com/user_avatar/www.phphelp.com/strider64/32/3161_2.png) [@Strider64](https://www.phphelp.com/u/Strider64)\
**Post date:** [April 11, 2023, 11:58am UTC](https://www.phphelp.com/t/problem-to-get-my-real-ip-on-ios/35391/4 "2023-04-11T11:58:29Z")

</div>

> [@Belinda](#):
>
> Yes, but why is it that on all sites they show the correct IP (on iOS), but I don’t.

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.

---

<div class="post-metadata">

**Author:** ![Belinda](https://www.phphelp.com/user_avatar/www.phphelp.com/belinda/32/4330_2.png) [@Belinda](https://www.phphelp.com/u/Belinda)\
**Post date:** [April 12, 2023, 9:38am UTC](https://www.phphelp.com/t/problem-to-get-my-real-ip-on-ios/35391/5 "2023-04-12T09:38:25Z")

</div>

> [@Strider64](#):
>
> 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.

If i go on this little real site website : [http://monip.org/](http://monip.org/)

It’s show my real IP. He don’t use script so..
