User ip function is giving server's ip

Hello all,

I am using:


Yii::$app->getRequest()->getUserIP()

to get user’s ip address. The problem is that this function gives me an IP address of the server, not the user’s one.

What can be the problem related to?

If you check Request source code:




    public function getUserIP()

    {

        return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;

    }



So you will get the right parameter. Do you internally use some kind of proxy?

I don’t use proxy.

This issue related to any user which is using a website.

For example, when user is registering, scripts gets user’s IP address and inserts in the database, however right now they (IPs) are all the same, because of this issue.

Any clue?

Use more universal way for getting IP-address: http://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php

REMOTE_ADDR - just one of ways. It’s not accurate.

Thank you. This helped me.