CodeIgniter Forums
How CI handles PHP native sessions ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: How CI handles PHP native sessions ? (/showthread.php?tid=2711)



How CI handles PHP native sessions ? - El Forum - 08-20-2007

[eluser]Référencement Google[/eluser]
Hi,

I am not sure about how do CI handles native PHP sessions ($_SESSIONS) because I get problems, it seems that my sessions are not kept between pages.

I have a library to manage sessions from DB (db_session) but I would like also to use some sessions as the classic way, having for some things the use of the DB, and for some other things the use of native sessions.

Some code maybe will help:

config.php
Code:
$config['sess_cookie_name']        = 'NipX';
$config['sess_expiration']        = 7200;
$config['sess_encrypt_cookie']    = TRUE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']        = 'ci_sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent']    = FALSE;

$config['cookie_prefix']    = "";
$config['cookie_domain']    = "";
$config['cookie_path']        = "/";

Some controller part:
Code:
if(!isset($_SESSION['category']))
        {
            $_SESSION['category'] = $this->view_category();
            echo $_SESSION['category']; // for debugging
        }

        $this->category = $_SESSION['category'];

Unfortunally at each page load, the session value is changed, in a classic PHP script, it wouldn't be...

Could somebody help ?


How CI handles PHP native sessions ? - El Forum - 08-20-2007

[eluser]rhkdmbd[/eluser]
I think CI destroys the $_SESSION array on every page request, which is why you are losing session values between pages.

If you want to use sessions you'll probably have to use the CI session library.

This might help: http://ellislab.com/codeigniter/user-guide/libraries/sessions.html


How CI handles PHP native sessions ? - El Forum - 08-20-2007

[eluser]Rick Jolly[/eluser]
You can use $_SESSION - CI doesn't destroy php native sessions. I find it is more flexible than CI sessions.

Did you remember to call session_start(); before accessing $_SESSION?


How CI handles PHP native sessions ? - El Forum - 08-20-2007

[eluser]rhkdmbd[/eluser]
Really?
I thought I'd read somewhere that it clears it out every time...
Oh well, I guess if it works for you you must be right.

I've always wanted to use native sessions but could never get them working properly in CI Tongue


How CI handles PHP native sessions ? - El Forum - 08-20-2007

[eluser]Derek Allard[/eluser]
You're probably thinking of the CI session class... but it doesn't touch the session array.

elitemedia, if you really want to use PHP native sessions, check out the native session library.


How CI handles PHP native sessions ? - El Forum - 08-21-2007

[eluser]Référencement Google[/eluser]
Quote:Did you remember to call session_start(); before accessing $_SESSION?

Ho !!! So stupid I am !
With the framework, I sometimes forget all the basics of PHP... :ohh:
Sure it works now, thanks !

> Derek: Thank you, I will check that library, looks usefull.

Christophe