Welcome Guest, Not a member yet? Register   Sign In
Dynamic Base URL Destroys Session
#1

[eluser]Mr Lazy[/eluser]
Hello,

I am dynamically changing the base url from a DNS name to an IP address (if the client's IP address is within a certain range), but in doing this, the session data is destroyed. In config.php I have:

Code:
$config['sess_cookie_name']       = 'ci_session';
$config['sess_expiration']        = 3600;
$config['sess_encrypt_cookie']    = FALSE;
$config['sess_use_database']      = FALSE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']          = FALSE;
$config['sess_match_useragent']   = TRUE;
$config['sess_time_to_update']    = 300;
I thought 'sess_match_ip' might have been the issue, but then I discovered it is set to FALSE by default. If I access the application using an IP address instead of the DNS name (and within the IP range), the session is not destroyed. So it must be something to do with changing the url from:
http://example.com/login
to
http://123.123.123.1/login

Can anyone help me and shed any light on this?

Many Thanks,
L
#2

[eluser]Wuushu[/eluser]
Your session identifier cookie (the one and same) is not available on both domains, your DNS name domain, and your IP-address "domain". So when the user travels from one to the other, the user gets treated as a new visitors discarding old session data.

Just a guess.
#3

[eluser]Mr Lazy[/eluser]
Right OK, that makes sense. So if I want to keep the session alive across domains, any suggestions how that may be possible?

Or another solution (that has just popped into my head), is to redirect the user to the new IP address before setting the session... mmmm...

Thanks

L
#4

[eluser]xeroblast[/eluser]
i dunno if i get this right..


try setting a cookie in the example.com like this set_cookie(array('name' => 'the name', 'value' => 'the value', 'domain' => '.123.123.123.1'));

then in your 123.123.123.1 domain get the cookie like this get_cookie('the name');

i dunno if i implement it correctly...
#5

[eluser]Mr Lazy[/eluser]
OK, thanks for the help and suggestions but I solved the issue upstream before the request gets to CI. Probably a better solution in the end...




Theme © iAndrew 2016 - Forum software by © MyBB