$this->session->sess_destroy(); error |
A PHP Error was encountered
Severity: Warning Message: session_destroy(): Trying to destroy uninitialized session Filename: Session/Session.php Line Number: 627 http://stackoverflow.com/questions/57528...on-destroy If you need to just delete the session if it exists (for example in an auto called exit/logout/destructor script) and it may or may not exist, then you can use session_status to check the status. As of PHP 5.4.0, you can check it like this: if(session_status() == PHP_SESSION_ACTIVE) { session_destroy(); } This is preferable to creating a new section just to destroy it later. Per the PHP manual, session_status will return an integer that can be compared with the following constants: Return Values • PHP_SESSION_DISABLED - Returned if sessions are disabled. • PHP_SESSION_NONE - Returned if sessions are enabled, but none exists. • PHP_SESSION_ACTIVE - Returned if sessions are enabled, and one exists. This allows you to write better, more efficient, and more flexible session management code. (04-04-2016, 11:30 PM)chaegumi Wrote: A PHP Error was encountered Did you have load Session Library ? Maybe in config.php like this ? $autoload['libraries'] = array('database', 'session'); (04-05-2016, 01:58 AM)projack89 Wrote:(04-04-2016, 11:30 PM)chaegumi Wrote: A PHP Error was encountered yes, autoload.php
04-05-2016, 03:01 AM
(This post was last modified: 04-05-2016, 06:12 AM by josepostiga. Edit Reason: Bad suggestion (thanks Narf) )
The Session library should be autoloaded as a driver, and not as a library... So, instead of adding it to the $autoload['libraries'] array, it should be added to the $autoload['drivers'] array, like this: $autoload['drivers'] = array('session');
Best regards,
José Postiga Senior Backend Developer (04-05-2016, 03:01 AM)josepostiga Wrote: The Session library should be autoloaded as a driver, and not as a library... So, instead of adding it to the $autoload['libraries'] array, it should be added to the $autoload['drivers'] array, like this: $autoload['drivers'] = array('session'); No, it shouldn't!
(04-05-2016, 05:00 AM)Narf Wrote:(04-05-2016, 03:01 AM)josepostiga Wrote: The Session library should be autoloaded as a driver, and not as a library... So, instead of adding it to the $autoload['libraries'] array, it should be added to the $autoload['drivers'] array, like this: $autoload['drivers'] = array('session'); Ok, why not? Because the Session driver/library (whatever) has the options for different drivers (files, database, etc)... If I'm that wrong, can you please help me understand the difference? If that's not to troublesome for you, of course...
Best regards,
José Postiga Senior Backend Developer
What do you mean why not? You can't arbitrarily make-up a rule and then ask why it is not true.
- The documentation says it's loaded via $this->load->library() (and NOT $this->load->driver()). - The database "library" also has drivers, and it's not loaded via $autoload['drivers']. - The inline documentation (comments in the autoload.php file itself) above $autoload['drivers']) says "they extend the CI_Driver_Library class"; the Session library does not extend that class. That last one has been explained in other topics around here too.
(04-05-2016, 05:50 AM)Narf Wrote: What do you mean why not? You can't arbitrarily make-up a rule and then ask why it is not true. Narf, I was not making an arbitrary rule. I can't recall right now why, but I've been using it like that since version 3.0-dev... The "why not" portion of my question must've been misinterpreted, or badly used by me on my sentence (and probably the bold part didn't helped either), but I was trying to learn about my mistake and asked simply for a better explanation other than a bold DO NOT DO THAT reply. I think that I have the right to be wrong but I appreciate that you (or anyone else) points when that happens. However if I don't ask why I'm wrong, then how am I supposed to learn from it? Your explanation, although it answers my question, "sounds" a little too raw and a little mean (lacking a better word). Nevertheless, thank you for your response. I've updated my reply above so the user ignores it completely.
Best regards,
José Postiga Senior Backend Developer
FFS, stop interpreting everything I write as being mean.
For a lengthy period of time, there was a version of the session library that used CI_Driver_Library and that was indeed the case. But that's in the past.
@josepostiga this is the 2nd time you have posted a way to do something on this forum that is either bad practice, specific to your application, against typical codeigniter/php. While I and many others on this forum enjoy reading different ways to do things, please make sure what you're posting is correct and valid ways to do things in PHP and CI applications.
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
|
Welcome Guest, Not a member yet? Register Sign In |