function getUserIP() returns local ip address if the servers are behind load balancer (i am using aws)
public function getUserIP()
{
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
}
i need to change it to each time i upgrade my framework
return (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : null;
is there any way i can override the function in my config file or somewhere so i can still use it for logging purpose.
Yes.
\yii\web\Request.getUserIP().request component.or overwrite $_SERVER['REMOTE_ADDR'] in index.php
hello, what do you think if we implement this functionality like in symphony ?
Via separate method? Yes, that's OK.
@samdark I suggest to reimplement getUserIP which should use trustedHeaders property of request object and make docs how it influence to security.
related to #10854 and #13050
closing as duplicate of #10854
Most helpful comment
Yes.
\yii\web\Request.getUserIP().requestcomponent.