• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CI Session Unexpected Behavior on Production

#1
[eluser]resajregit[/eluser]
Hello Folks!

I can use some help with this one. It's definitely one of those stump the chump type situations.

Ok, so I've created this site, http://uat.nimerism.com/, which works like a charm on localhost. On production however, the login feature does not work properly. It has something to do with sessions.

The way it should work is that when a user enters the correct username and password, a session is created using CI database sessions with some "user data" and the page is reloaded. When the page loads, it checks for that user data in the session, and if it's found a specific javascript file is loaded to the header, which in turn enables some CMS functionality to the site (buttons and such).

What appears to be the issue is that multiple sessions records are created in the sessions table (I'm using database sessions), which causes this statement
Code:
$this->session->userdata('username')
to return blank, which causes the javascript to not get loaded. I'm not sure why multiple records for the same IP address are created on production, but only one is created for local host.

Here's what I've attempted already:

Used local sessions (not database)
enabled sess_match_ip in config.php

Any help will be much appreciated.

TJ

#2
[eluser]skunkbad[/eluser]
I always hear people suggest that you make sure the server time is accurate. Maybe if your server time is corrected your cookie will behave?

#3
[eluser]resajregit[/eluser]
Thanks for the suggestion - I noticed that the timezone differ on production and localhost, but is changing that on the server to match the client really a realistic solution here? What if I decide to log in while on the beach in Thailand? Besides that, I don't think I can change the time on the server. Any other suggestion?

UPDATE: It's definitely a timely issue. When I wait a several minutes, and refresh the page the missing functionality appears. Which explains why it works on localhost(client and server have the same time). What do I do?


#4
[eluser]skunkbad[/eluser]
I believe the idea is that because of timezone differences, if the cookie is set to expire, but the time it is set to expire is actually in the past, then it immediately expires. All you would have to do to check would be look at the cookie details in your browser. Honestly, I don't know what the answer would be, except to set the cookie expires time to 0, or set it out a few hours to compensate.

If you need to set the time of the server ... You'd probably have to talk with the server admin.

#5
[eluser]resajregit[/eluser]
I don't think the timezone is the problem here. Immediately upon authentication, the session table in the database will have 3 new records added to it. So, when I go back to check if the user data is present, it returns false, because it's returning the first row that matches, which does not have the user data. Just a thought.

#6
[eluser]skunkbad[/eluser]
If you enable the profiler, do you see that the records are actually being created?

#7
[eluser]resajregit[/eluser]
Good idea! Yes, there are three insert statements in total. Strangely enough, they only show up for the three sections that I added to the site recently (Header, Critiques, and Site map). I left the profiler on for you to see. I think we're getting close.

EDIT: I'll take that back. I only activated the profiler for on controller (home) that's why the statements showed up three times. I think the correct logic is that for those three section of the site, which are loaded by calling a function in the home controller, a session record is created because that controller specifically checks for the user data in the session.

#8
[eluser]InsiteFX[/eluser]
Also make sure that you have the correct ci_session table.

Code:
-- ------------------------------------------------------------------------

--
-- Table structure for CodeIgniter ci_sessions.
--
DROP TABLE IF EXISTS `ci_sessions`;

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
  `session_id`    varchar(40)           DEFAULT '0' NOT NULL,
  `ip_address`    varchar(16)           DEFAULT '0' NOT NULL,
  `user_agent`    varchar(120)                      NOT NULL,
  `last_activity` int(10)      unsigned DEFAULT 0   NOT NULL,
  `user_data`     text,
  PRIMARY KEY (`session_id`),
  KEY `last_activity_idx` (`last_activity`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;

-- ------------------------------------------------------------------------
--  `user_data` text,       COMMENT - maximum length of 65535 characters.
--  `user_data` mediumtext, COMMENT - maximum length of 16777215 characters.
--  `user_data` longtext,   COMMENT - maximum length of 4294967295 characters.
-- ------------------------------------------------------------------------


#9
[eluser]resajregit[/eluser]
I figured it out!

Caching! I had the following in my controller:

Code:
$this->output->cache(5);

which explains the delay. Boy do I feel stupid.

Thanks for the help.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.