简体   繁体   中英

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, ie 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 on 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"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM