Welcome Guest, Not a member yet? Register   Sign In
Sessions, some work, some donn't.
#1

[eluser]smick[/eluser]
Hi,

I've been using Codeigniter for a few years now and today I ran into a session problem. I've had these issues with nearly every site I've developer with codeigniter, and it is sad that it keeps being a problem.

I have a number of sessions that are used across the site, and they work well.

But I'm trying to set a simple session in a model file and I'm getting strange results.

I have the following code:

Code:
if(isset($_POST['category'])) {
                //echo("submitted");
                $category = $this->input->post('category');
                echo("category: $category<br>");
                if($this->session->set_userdata("category", $category)) { echo("session set"); }
                else { echo("session set failed<br>"); }
                echo("category specified, set to: $category " . $this->session->userdata('category') );
            }
            else {
                $category = $this->session->userdata('category');
                echo("no category specified, setting category to: $category " . $this->session->userdata('category'));
            }

It outputs this on first run, when the category post data is sent:

Quote:category: 15
session set failed
category specified, set to: 15 15

When I reload the page without sending the category post data it responds:

Quote:no category specified, setting category to:


This is so strange, because on first run, it fails to set the session variable, but then is able to retrieve the session variable for reporting purposes. Then when I load the page without the post data, it cannot retrieve the session data.

Anyone know what I'm doing wrong?

I have my session config set to the following:

Code:
$config['sess_cookie_name']        = 'RM_sessions';
$config['sess_expiration']        = 60 * 60 * 24 * 30;
$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;



and my cookie config set thus:

Code:
$config['cookie_prefix']    = "RM_";
$config['cookie_domain']    = "http://recipematcher.com";
$config['cookie_path']        = "/";



Thanks for any help!
#2

[eluser]jedd[/eluser]
I posted links to four other threads on this subject here: [url="http://ellislab.com/forums/viewthread/148442/"]http://ellislab.com/forums/viewthread/148442/[/url]

Obvious thing to try (apart from a more scientific / logical approach to problem solving) is removing the underscore.
#3

[eluser]DisturbedMind[/eluser]
Like jedd mentioned, there is a known issue with IE6 and cookies that contain an underscore. Try removing the underscore and see if that resolved your issue.
#4

[eluser]smick[/eluser]
thanks, my issue is actually with all browsers. I'm trying to dig through all the content but it's taking a while and nothing I've tried has worked yet. I know it's most likely either an issue with the domain or expiration, but haven't figured it out yet.
#5

[eluser]jedd[/eluser]
[quote author="smick" date="1268295690"]
my issue is actually with all browsers.
[/quote]

That's a very interesting - though likely untested / purely speculative - bit of information that could be provided early on.

Actually - 'I have tested with versions i, j, k of browsers x, y, and z' - would be far more interesting.

I tend to not trust people that say things like 'this works with all browsers'. Call me old-fashioned.

Remove underscores (I'm having deja vu) and try again. Confirm synchronised dates between server and client and try again. Etc.
#6

[eluser]smick[/eluser]
Interesting? You're having trust issues with me? WTF dude! Drop the bullshit guru/troll attitude if you're going to be involved in this. When I say it's all browsers, I mean it's not the IE 6,7,8 problem that people are having with underscores and/or domain underscores.

I have wacky sessions, and yes, I know it's likely either a problem with the server time/expiration, or maybe the domain path. I've tried setting the expiration to way in the future, and I've tried changing the server time, etc., nothing has worked yet.

Tested in Firefox, IE and Chrome. Expression to set session fails an if statement, then I'm oddly enough able to retrieve the session data that was reported as failed, then on page reload session data unavailable, as though it did fail. Also, standard sessions don't seem to be working either. Though I haven't tried unloading the session library when testing that. The session library might be hijacking the cookie golbal functions causing standard sessions not to work properly.


For whatever reason sessions aren't writing, at least not in the model, and I haven't been able to figure out why. I feel like it's most likely a path issue. I'm running on a staging server in a nested directory, would I need to put my directory after the domain?
#7

[eluser]petewulf[/eluser]
Hello there,

smick is right, there is really a Session problem in CI.
The last time i tried to deal with the build in Session Management i ran into the problem that my Session is lost from one click to the other, so i decided not to use the CI Sessions any more and get back to the good old native PHP functions.

Regards, Pete
#8

[eluser]smick[/eluser]
oddly enough standard php sessions aren't working either. I've dug through everything in the links and haven't found a solution yet. I'm running a slightly older version of CI so I'm hesitant to try the sessions library edits.

Flash data is working, for what it's worth.


My server time is correct.
My sessions are set to non expiring, though I've tested it with time limits.
My sessions are set to the same url as my site, I've experimented with different settings. I am forcing the 'www' prefix through .htaccess, and my cookies are showing that as the domain.

Nothing seems to fix the problem. it seems like the session write function isn't working at all.


Very annoying! I've invested too much time in CI for this to be such a common headache.

I'm running a very large website and upgrading CI is probably going to be a nightmare!
#9

[eluser]smick[/eluser]
HOw can I figure out what version of CI I'm running?
#10

[eluser]smick[/eluser]
nevermind, found it in the codeigniter.php file. Attempting an upgrade




Theme © iAndrew 2016 - Forum software by © MyBB