03-13-2017, 02:39 PM
(This post was last modified: 03-13-2017, 02:39 PM by gdhnz.)
I've got some proxy IPs set in my config but I've found out if you set $config['sess_match_ip'] = true, then the Session library will not take into account the proxies and will always use $_SERVER['REMOTE_HOST'].
$this->input->ip_address() does take into account the proxy IPs and returns the correct client IP.
Just use $this->input->ip_address() and assign it to your session variables.
What did you Try? What did you Get? What did you Expect?
Joined the CodeIgniter Community in 2009. ( Skype: insitfx )
03-13-2017, 03:59 PM
(This post was last modified: 03-13-2017, 03:59 PM by gdhnz.)
I've overridden the relevant session driver to set the $CI->input->ip_address() value to a $this->ip_address class variable in the driver constructor and have replaced all instances of $_SERVER['REMOTE_ADDR'] with $this->ip_address.
Is it worth providing a pull request updating all the session drivers?
No, this is by design and I suggest that you reverse your changes.
If you don't want me to provide a PR then that's fine but I'm not going to revert my local changes with no explanation when it's doing what I require.
If it makes any difference to the explanation, I'm on CI v3.1.3.
Our web setup uses docker containers behind some proxies. What I see when I use match_ip for sessions is the ip address of the proxies.
All I've done is copy the system/libraries/Sessions/drivers/Session_redis_driver.php file to application/libraries/Sessions/drivers/MY_Session_redis_driver.php and just overrode the methods that used $_SERVER['REMOTE_ADDR'].
According to the documentation, this how you override core files.