Welcome Guest, Not a member yet? Register   Sign In
Sessions - Not Working
#1

(This post was last modified: 07-02-2015, 09:24 AM by iD30.)

Hi All

I have recently updated form 2.2.x to 3.0.0 - following the update procedure from codeigniter's website HERE.

I have having real issues with the new session library - heres the issue.

We have a login section which dependant on the subdomain and user/pass credentials will give you certain privileges from ADMIN / RESELLER / CLIENT / USER

In order to determine the correct privileges for the user we have built a customer LIBRARY (location:application/library) which we have called Session_management, this library DOES NOT extend the core SESSION driver/library and never has and has no extension to another class, this library is also auto-loaded, prior to CI 3.0.0 everything was working fine.

First this the Session_management does is __construct()

Code:
               $this->CI =& get_instance();
$this->CI->load->model('users');
$this->CI->load->model('clients');
$this->CI->load->model('sessions');
$this->CI->load->driver('session');
$this->CI->load->library('password_hash');
$this->CI->load->helper('url');

$this->users = $this->CI->users;
$this->clients = $this->CI->clients;
$this->sessions = $this->CI->sessions;
$this->session = $this->CI->session;
$this->password_hash = $this->CI->password_hash;

Prior to CI 3.0.0 I has no issues in using the
Code:
$this->CI->load->library('session')
but for some unknown reason (to me) I have to load it through the driver
Code:
$this->CI->load->diver('session');
- if someone could explain why this is would be great.

When a user submits their user/pass credentials a CONTROLLER session/signin is requested which runs firstly form validation, providing everything is successfully, the Session_management login method is called.

Code:
$success = $this->session_management->login($this->input->post('email'), $this->input->post('password'));

In the LOGIN method in the Session_management class a bunch of sessions are set using $this->session->set_userdata()
Code:
               $this->session->set_userdata('user_id', 0);
$this->session->set_userdata('user_name', '');
$this->session->set_userdata('client_id', 0);
$this->session->set_userdata('client_administrator', 0);
$this->session->set_userdata('reseller_administrator', 0);

However when I var_dump() the session for all its session data it has NOTHING and I can't why this is, no session data is there except my protected fields form the config, which I have double checked and triple checked and are working fine, my sess_save_path is storing the session files correctly, and the rest of the sess configs are also correct.

Code:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = '/Users/******/Sites/********/tmp';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

This is a development website on my local OS X iMac, as I say prior to CI 3.0.0 everything was working fine.

Any help or information or anything that could possible put me in the right direction would be appreciated.

Michael
Reply
#2

You are wrong about loading the session as a driver.
Just like before, it must be loaded as a library:
PHP Code:
$this->load->library('session'); 
Check the documentation for that.

The tricky part is configuring the session settings.
I didn't get it working with $config['sess_driver'] = 'files';
Therefore, I switched to $config['sess_driver'] = 'database';  and I added a ci_sessions table to my database.
No problems with sessions since then.
Reply
#3

(06-25-2015, 10:34 AM)Wouter60 Wrote: You are wrong about loading the session as a driver.
Just like before, it must be loaded as a library:

PHP Code:
$this->load->library('session'); 
Check the documentation for that.

The tricky part is configuring the session settings.
I didn't get it working with $config['sess_driver'] = 'files';
Therefore, I switched to $config['sess_driver'] = 'database';  and I added a ci_sessions table to my database.
No problems with sessions since then.

Just to add to this message re: database sessions. Database sessions were my first option, a have revamp the database columns and indexes to suit CI 3.0.0 as the documentation mentions and session were and are storing when I change my config to use the database, however reading the performance differences between Files against Database under high load, File sessions will out perform database session and since the website / platform I am creating will be under high load, database sessions aren't the way forward.
Reply
#4

(06-25-2015, 10:34 AM)Wouter60 Wrote: You are wrong about loading the session as a driver.
Just like before, it must be loaded as a library:







PHP Code:
$this->load->library('session'); 
Check the documentation for that.

The tricky part is configuring the session settings.
I didn't get it working with $config['sess_driver'] = 'files';
Therefore, I switched to $config['sess_driver'] = 'database';  and I added a ci_sessions table to my database.
No problems with sessions since then.

Thanks for your reply Wouter60, however, in my problem I said I "HAVE" to load it as a driver, I don't have a choice, I also asked if someone could explain why I have that would be great. I have read the documentation and have seen how to initialise the session library -  http://www.codeigniter.com/userguide3/li...-a-session 

If I do attempt to load it as a library
Code:
$this->load->library('session')

This is what I get
Code:
A PHP Error was encountered

Severity: Notice
Message: Undefined property: Session::$session
Filename: libraries/Session_management.php
Line Number: 38

For your ref: line 38 is:
Code:
$this->session = $this->CI->session;

This is after trying to load the session library
Code:
$this->CI->load->library('session');

Any further help would be appreciated
Reply
#5

I assume you've copy-pasted the new CI files over the old ones instead of deleting the old system/ directory and putting the new one in its place ... If that's the case - delete system/libraries/Session.php.
Reply
#6

(06-26-2015, 02:59 AM)Narf Wrote: I assume you've copy-pasted the new CI files over the old ones instead of deleting the old system/ directory and putting the new one in its place ... If that's the case - delete system/libraries/Session.php.

Thanks for your reply Narf, I really thought you were on to something then.

I have just checked my system dir for the redundant/stray Session.php but it wasn't there, to double make sure I have just removed the old System dir and added the new CI 3.0.0 System dir in its place.

Any further help would be appreciated.
Reply
#7

(06-26-2015, 03:04 AM)iD30 Wrote:
(06-26-2015, 02:59 AM)Narf Wrote: I assume you've copy-pasted the new CI files over the old ones instead of deleting the old system/ directory and putting the new one in its place ... If that's the case - delete system/libraries/Session.php.

Thanks for your reply Narf, I really thought you were on to something then.

I have just checked my system dir for the redundant/stray Session.php but it wasn't there, to double make sure I have just removed the old System dir and added the new CI 3.0.0 System dir in its place.

Any further help would be appreciated.

Well, then there's nothing left but to check your log files, that's what you should've done in the first place.
Reply
#8

(This post was last modified: 06-26-2015, 03:34 AM by iD30.)

(06-26-2015, 03:22 AM)Narf Wrote:
(06-26-2015, 03:04 AM)iD30 Wrote:
(06-26-2015, 02:59 AM)Narf Wrote: I assume you've copy-pasted the new CI files over the old ones instead of deleting the old system/ directory and putting the new one in its place ... If that's the case - delete system/libraries/Session.php.

Thanks for your reply Narf, I really thought you were on to something then.

I have just checked my system dir for the redundant/stray Session.php but it wasn't there, to double make sure I have just removed the old System dir and added the new CI 3.0.0 System dir in its place.

Any further help would be appreciated.

Well, then there's nothing left but to check your log files, that's what you should've done in the first place.

Without trying to sound disrespectful to you Narf, but I find your remark rather insulting "check your log files, that's what you should've done in the first place".

Do you honestly think I would of wasted my time, Codeigniter's forum members time with a write up of my issue and gone through the whole process to NOT have checked my log files. 

Every project I am working on,  I run tail -f on my log files to give me live log updates.

Thanks for your time and "advice" Narf.
Reply
#9

(06-26-2015, 03:33 AM)iD30 Wrote:
(06-26-2015, 03:22 AM)Narf Wrote:
(06-26-2015, 03:04 AM)iD30 Wrote:
(06-26-2015, 02:59 AM)Narf Wrote: I assume you've copy-pasted the new CI files over the old ones instead of deleting the old system/ directory and putting the new one in its place ... If that's the case - delete system/libraries/Session.php.

Thanks for your reply Narf, I really thought you were on to something then.

I have just checked my system dir for the redundant/stray Session.php but it wasn't there, to double make sure I have just removed the old System dir and added the new CI 3.0.0 System dir in its place.

Any further help would be appreciated.

Well, then there's nothing left but to check your log files, that's what you should've done in the first place.

Without trying to sound disrespectful to you Narf, but I find your remark rather insulting "check your log files, that's what you should've done in the first place".

Do you honestly think I would of wasted my time, Codeigniter's forum members time with a write up of my issue and gone through the whole process to NOT have checked my log files. 

Every project I am working on,  I run tail -f on my log files to give me live log updates.

Thanks for your time and "advice" Narf.

So I was wrong in assuming that you didn't check your log files. Yet none of your posts mention the word "log" or include any log output ...

Yes, I honestly did think that you didn't check your log files. Few people do, you're a first-time poster, and a LOT of people come here asking for help without making any effort to help themselves. Don't blame me for assuming that you haven't checked everything.
Reply
#10

@iD30

If
$this->CI->load->diver('session');
is still mysteriously needed, there are two more probable causes I can guess:

- Maybe the source you are using for upgrading is an old development snapshot CI 3.0-dev, not the final 3.0.0 release. For being sure, in your server check with
echo CI_VERSION;
what actually is returned.

- (Low probability) Presence of code execution accelerator like apc or another one, then it should be reset.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB