Override yii\base\Request getRemoteIP method

is it possibile to override the getRemoteIP() method with this below without modifying the core files? Can you in case write a short ‘how to’ to implement it? Thanks

public function getRemoteIP()
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
        $ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
        $ipAddress = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
    return $ipAddress;

Before you override this method - isn’t it better to use getUserIP()? It should deal with additional headers.

can you be more specific please?

Forgive me, I don’t know the reason you need to override that method, just assumed that maybe you need to get user’s IP and the one I pointed to seems to handle HTTP_X_FORWARDED_FOR (I’m not sure though).