[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!