Codeigniter Current Logged in user
In Codeigniter, I have a login/registration form all set up, working perfectly, however how can I output the current users username, i.e. When the user has logged in it would say "Welcome, [username]".
I also need to know this, to be able to output from the database the record based on the current users ID, how can I do that? I've browsed the docs o开发者_开发百科n codeigniter but couldn't find what i was looking for. I'm using active record btw.
Thanks
echo $this->session->userdata('name')
Incorporate that into the db select files as well, for instance if you have files that they created and you want to show them when they log in, use the session data in the db call as a where
I suggest you put all session data in the database as shown in session class.
http://codeigniter.com/user_guide/libraries/sessions.html
How is your login form performing the login action ? In most cases it's using session to identify that you are logged in. After you confirm (usually with database) that a user is OK drop user info in session (ID, readable name, and any other things you need) and next:
echo "Welcome " . $_SESSION["username"];
精彩评论