Invalid IP Address Returned



Error Message

I am creating a PHP script that redirects users to a specific link, however, before redirecting the user I use the API to obtain some specific information, such as country and state to generate reports of access to the links.
The problem is that the infinityfree proxy is getting in the way and returning me a False IP! Follow images.

Other Information

My Code

Returned IP Screenshot by Lightshot

My IP 191.XXX.137.XXX

Well you have some weird spaces and missing brackets, so maybe that may cause an issue? And I would not go changing a $_SERVER variable, especially since you are already using $ip.

You need to decide on one variable to use, and use one statement, not multiple, to obtain the IP. The only thing you need to test for is “CF-Connecting-IP”. See the docs


@Greenreader9 this function is just to check which of the indexers is set with the user’s IP and return the existing value inside the index in the variable $ip, nothing more.

The function looks incorrectly coded to me.

This is all you need:

    $user_ip = $_SERVER["HTTP_CF_CONNECTING_IP"];


I don’t know exactly how much paste2 displays

  1. (see how much space) thus broken into a new row has space
  2. but this should be in one line (2)
    no space or new line.

@Oxy the first line only existed to show me the api return array, it has already been removed.

Even so the command “$_SERVER[‘REMOTE_ADDR’];” keeps returning me a false IP.

I would like to know how to get the user’s real IP using infinityfree hosting, because in other hosting I can get the user’s real IP.

Because you are using Cloudflare. Please read my answers. I linked you the docs, and gave you the correct code.


Like This ?

function getUserIpAddr(){
} else {
return $ip;

@Greenreader9 even with the update in the code, I keep getting a Fake IP as a return.

Returned IP Screenshot by Lightshot
My real IP Screenshot by Lightshot

and now ? how do I proceed ?

You don’t use Cloudflare ! you should have pointed that out right away to @Greenreader9

address subsequently hidden by the moderator


@Oxy Yes, I don’t use cloudflare, however, I figured your system used the cloudfare proxy, so I didn’t say anything about it.

However, even though I’m not using cloudflare, it’s still returning a false IP.

How can I resolve this issue?

this returns the user IP

    echo 'User IP Address - '.$_SERVER['REMOTE_ADDR'];  

and you then fit it into a query string (geo) so it’s all in one line and no space

@Oxy I have already used this code and a False IP is returned in the same way.
That’s why I opened this topic on the forum, to ask for support, because I’ve already tested several ways to obtain IP with PHP and they all returned False IP.

let’s just take that code of mine
and put in a separate PHP file and visit it

and tell me which IP you see

here I made for you - please test

$user = $_SERVER['REMOTE_ADDR'];

$geo = var_export(unserialize(file_get_contents(''.$user)));

echo $geo;



@Oxy replace the function with the logic you passed and it worked, how strange…


Good luck in further work :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.