CodeIgniter Forums
Help with beginner login questions - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help with beginner login questions (/showthread.php?tid=16709)

Pages: 1 2 3


Help with beginner login questions - El Forum - 04-11-2009

[eluser]M4rc0[/eluser]
One question, my function above only works with session_id:

Code:
return ($CI->session->userdata('session_id')) ? TRUE : FALSE ;

and not with "logged_in" that I've set in the userdata for TRUE


After checking the database, I see that the ci_sessions table has the "user_data" field blank!

Why isn't storing my session there although it is set in the configuration to store in the database?


Help with beginner login questions - El Forum - 04-11-2009

[eluser]TheFuzzy0ne[/eluser]
Please post your config file (without any sensitive information). My database is being used for sessions and it's working properly. You're the first person I've heard of having this problem.


Help with beginner login questions - El Forum - 04-11-2009

[eluser]M4rc0[/eluser]
[quote author="TheFuzzy0ne" date="1239470453"]You're the first person I've heard of having this problem.[/quote]

Which increases the probability of me forgetting something Big Grin

Code:
$config['encryption_key'] = "somethinghere";

$config['sess_cookie_name']        = 'ci_session';
$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['sess_time_to_update']     = 300;

That's pretty much it. Cookie variables are default. Base url set correctly..

EDIT: Also my logout function is not working, I guess it's database related so I must fix this database session problem first


Help with beginner login questions - El Forum - 04-11-2009

[eluser]TheFuzzy0ne[/eluser]
Please could you give an example of how you're setting your userdata? I suspect you are using $this->sessions->userdata('key', 'value'), when it should be $this->sessions->set_userdata('key', 'value').


Help with beginner login questions - El Forum - 04-11-2009

[eluser]M4rc0[/eluser]
Code:
$sessionData = array(
           'session_id'=> md5(5),
           'id'     => 5,
                   'username'  => M4rc0,                  
                   'logged_in' => TRUE
               );
        $this->session->set_userdata($sessionData);  
        redirect('/home');

No warnigns no error and it redirect's to home, so it "works".


Help with beginner login questions - El Forum - 04-11-2009

[eluser]TheFuzzy0ne[/eluser]
This is a problem:
Code:
'username'  => M4rc0 # Undefined constant

I assume that in your code you've actually added quotes to this? If you didn't, it probably wouldn't redirect.

Can you actually retrieve the userdata on the next request, or is it empty? Also, just out of interest, why are you md5()ing the session ID? The cookie is encrypted already, so that's just a waste of CPU time, and cookie space. Smile


Help with beginner login questions - El Forum - 04-11-2009

[eluser]M4rc0[/eluser]
Oh that was just a data example. The real data are in variables coming from the model such as $login.
(And in this case $id was always empty, thus the problem..)

After checking the documentation again, I realized that session_id is for the cookie, not the userdata.
So I removed thanks to your md5 tip that made me rethink about it.

And now it works! storing in db and logging out Big Grin

So the real code in case someone else get this problem:
Code:
$sessionData = array(
            'id'     => $result,
                   'username'  => $login,                  
                   'logged_in' => TRUE
               );
                $this->session->set_userdata($sessionData);  
                redirect('/home');
So session_id is unnecessary to have in userdata, is that correct?

Thanks TheFuzzy0ne! Hope to hit with you in the forums more often later on Smile