0

I’m using Codeigniter for storing session data in the ci_sessions table. upon loading the webpage for the first time I get one cookie (which is okay) but at the same time I get two exactly same records (except for the session id) in my ci_session table. This is ridiculous as there should be only one for one user agent and IP combination.

Also when i tried another browser it started showing all of my browsers in the user_agent field for 1 record. this is driving me nuts. below is what i see in the user agent after using another browser to access my website. I’m going live very soon, please help!

user_agent

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36

My session table is as follows

#  Name         Type
1 session_id    varchar(40) 
2 ip_address    varchar(45) 
3 user_agent    varchar(255) 
4 last_activity int(10)
5 user_data     text
6 login_time    timestamp

And my session configuration is as follows

$config[‘sess_cookie_name’]  = ‘cisession’;
$config[‘sess_expiration’]  = 7200;
$config[‘sess_expire_on_close’] = TRUE;
$config[‘sess_encrypt_cookie’] = FALSE;
$config[‘sess_use_database’] = TRUE;
$config[‘sess_table_name’]  = ‘ci_sessions’;
$config[‘sess_match_ip’]  = TRUE;
$config[‘sess_match_useragent’] = TRUE;
$config[‘sess_time_to_update’] = 300;

FYI - I'm autoloading the session library.

2
  • Is it possible you have added an extension to your browser that has modified your user agent string? Look at what headers your browser is sending to make sure that isn't the problem. Commented Sep 14, 2013 at 15:06
  • Hi Brian, I've removed all extensions from chrome and safari but I still get the same result. I can confirm that it is not happening with Firefox but the problem of two records in the database is still an issue for me with all the browsers. Could you please explain why two sessions are getting created instead of one. If I close the browser the sessions stay there and another two are created for a fresh visit to the website. Commented Sep 14, 2013 at 16:45

1 Answer 1

0

I would try 2 things. First changing these lines:

$config['sess_encrypt_cookie'] = TRUE;
$config['sess_time_to_update'] = 30;

// also make sure you have set an encryption key
// you might like http://randomkeygen.com/
$config['encryption_key'] = '';

And then creating a .htaccess in your applications directory:

# Use Mod_deflate to compress static files
<ifmodule mod_deflate.c>
<filesmatch ".(js|css|ico|txt|htm|html|php)$">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>

# Speed up caching
FileETag MTime Size

# Expires
ExpiresActive On
ExpiresDefault "access plus 366 days"

# Future Expires Headers
<filesmatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Sat, 27 Dec 2014 23:59:59 GMT"
</filesmatch>

Reference: Codeigniter duplicate session issue

In my applications I place the following code into .htaccess for preventing a cookie to be sent with css/js/images requests

Regarding the user agent, that is actually correct how it's displaying. Here is a good/easy read that explains how the user agent string is composed: History of the browser user-agent string

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.