CodeIgniter Forums
$this->session->sess_destroy(); error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: Issues (https://forum.codeigniter.com/forum-19.html)
+--- Thread: $this->session->sess_destroy(); error (/thread-64864.html)

Pages: 1 2


$this->session->sess_destroy(); error - chaegumi - 04-04-2016

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/5752858/warning-session-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.


RE: $this->session->sess_destroy(); error - projack89 - 04-05-2016

(04-04-2016, 11:30 PM)chaegumi Wrote: 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/5752858/warning-session-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.

Did you have load Session Library ? Maybe in config.php like this ?
$autoload['libraries'] = array('database', 'session');


RE: $this->session->sess_destroy(); error - chaegumi - 04-05-2016

(04-05-2016, 01:58 AM)projack89 Wrote:
(04-04-2016, 11:30 PM)chaegumi Wrote: 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/5752858/warning-session-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.

Did you have load Session Library ? Maybe in config.php like this ?
$autoload['libraries'] = array('database', 'session');

yes, autoload.php


RE: $this->session->sess_destroy(); error - josepostiga - 04-05-2016

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');


RE: $this->session->sess_destroy(); error - Narf - 04-05-2016

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


RE: $this->session->sess_destroy(); error - josepostiga - 04-05-2016

(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');

No, it shouldn't!

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...


RE: $this->session->sess_destroy(); error - Narf - 04-05-2016

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.


RE: $this->session->sess_destroy(); error - josepostiga - 04-05-2016

(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.

- 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.

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.


RE: $this->session->sess_destroy(); error - Narf - 04-05-2016

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.


RE: $this->session->sess_destroy(); error - albertleao - 04-05-2016

@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.