[solved]Passing values from a record in a session? - 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: [solved]Passing values from a record in a session? (/showthread.php?tid=42917) |
[solved]Passing values from a record in a session? - El Forum - 06-23-2011 [eluser]brucebat[/eluser] Hey all, Im wanting to store the following variables: -username -access_level -user_id Within an array that is stored in the session. Right now I am storing my username by using the "post" function after a user logs in. However I want to get all the info from the corresponding record in the database. I have tried this: Code: $user_session = array ( Is this correct way of going about it? [solved]Passing values from a record in a session? - El Forum - 06-23-2011 [eluser]toopay[/eluser] Suppose we are in a method which receive the $_POST variable, you easily can do... Code: function login() [solved]Passing values from a record in a session? - El Forum - 06-27-2011 [eluser]brucebat[/eluser] Thanks for your reply toopay. Im still having problems with this code. Code: function authenticate() It seems to be compiling but my site is not responding to this session being created e.g. Navigaation menu changing and different links being displayed. Sorry to be a pest! [solved]Passing values from a record in a session? - El Forum - 06-27-2011 [eluser]cideveloper[/eluser] Is the session autoloaded? Check your db after successful login and see if the array is in there. [solved]Passing values from a record in a session? - El Forum - 06-27-2011 [eluser]brucebat[/eluser] Yes it is autoloaded. I dont understand what you mean by checking my database to find an array in there? Sorry This was my original code but this only stored a variable "username" taken from post Code: if($query) // if the user's credentials validated... Want I want is once the user is found I want to store in my session their: userID - name -used for displaying in the user control panel username - will be used for retrieving other info access_level - to control what pages users can see The table where this is all held in is called "user". What I want is to take those columns from that table and store them in a session. ----------- The older bit of code was working before but it is not sophisticated enough to allow me to implement my navigation and admin control panel that I want on the site. Thanks for your time! [solved]Passing values from a record in a session? - El Forum - 06-27-2011 [eluser]cideveloper[/eluser] Ok. looking at the authenticate function, you should do this. In your validate function in the model you are returning either true or false based on whether the user is authenticated or not. If they are authenticated then you should set the session variables in the model. In the validate function you are probably selecting a row based on the criteria in your post. If the row is there you are returning true. before you do your return set the session value. Code: $username = $this->input->post('username', true); Then in your controllers get the "user" session value Code: $data['user_session'] = $this->session->userdata('user'); and pass it to your views. In you views you will be able to access each variable as such Code: <?php echo $user_session['name'];?> [solved]Passing values from a record in a session? - El Forum - 06-27-2011 [eluser]brucebat[/eluser] Thanks: Im still having problems with the logic, I try to echo some user session stuff or check they are set and its saying undefined variable. Or it is not doing anything. login_model/validate() Code: function validate() login controller Code: function authenticate() control panel view Code: <?php I am really confused with all the documentation with: set_userdata $userdata setuserdata etc This is all still very alien to me from what im used to in C++ Thanks for your time. [solved]Passing values from a record in a session? - El Forum - 06-27-2011 [eluser]cideveloper[/eluser] if you want to do it that way change the model to this. Code: function validate() [solved]Passing values from a record in a session? - El Forum - 06-27-2011 [eluser]brucebat[/eluser] Thankyou very much, I figured out what was the actual culprit of my problem, I forgot my md5 on the password Code: $this->db->where('password', md5($this->input->post('password'))); Thankyou for being patient with me and a great help. Regards Bruce [solved]Passing values from a record in a session? - El Forum - 04-06-2012 [eluser]elektra[/eluser] Hi I'm fairly new to codeigniter and I'm actually having the same problem but can't seem to figure out why. All I want is to retrieve few user data so I could echo them out when they logged in. Really need help and running out of time. Thank you. Controller Code: $query = $this->User_model->validate_login(); Code: public function validate_login() Code: <?php if($this->session->userdata('logged_in') == TRUE): ?> |