Session system - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Session system (/showthread.php?tid=69794) Pages:
1
2
|
Session system - florent6001 - 01-18-2018 Hi all, i want to get all my informations into my session storage into the login, i dont know how to do this. Here is my code: My controllers: Code: public function login(){ My Model: Code: public function getSessionData($username){ RE: Session system - PaulD - 01-18-2018 Personally I never use the userdata functions. I just access the $_SESSION variable directly. I actually thought they were deprecated but checking the session library docs I cannot confirm that - I must have been wrong. If you have an array of user_data you can just set it like this: PHP Code: $_SESSION['user_info'] = $user_data; I would not use a wildcard select though, I would create my user_data array more carefully and only include the info that was absolutely necessary. I also assume you are using a database table for sessions so you have plenty of storage space instead of using cookies. On a final note, this appears to be a login procedure, but it seems very insecure. Also not very user friendly. After you have shown the home page after login, a refresh will cause the page to try to resubmit the login post details. Have a look at ionauth. It is a very useful and easy to use CI library to do authorisation and authentication with many powerful features. Best wishes, Paul. RE: Session system - florent6001 - 01-19-2018 How can i set like this: $_SESSION['username'] = $username $_SESSION['administrator'] = $dbresultadministrator RE: Session system - florent6001 - 01-19-2018 Undefined variable query RE: Session system - InsiteFX - 01-19-2018 Because you are doing it wrong. PHP Code: $query = $this->user_model->getSessionData($this->input->post('username')); RE: Session system - florent6001 - 01-19-2018 I copyed your code, your logic is good but i have this error: Type: Error Message: Call to a member function result_array() on null Filename: /homepages/30/d697615061/htdocs/preprod/application/controllers/Users.php Line Number: 44 RE: Session system - florent6001 - 01-19-2018 Model: Code: public function login($username, $enc_password){ Controllers: Code: public function login(){ My var_dump of $query is null RE: Session system - ciadmin - 01-19-2018 Your getSessionData doesn't return anything, so of course the result, when you try to use it in your controller, is null. At the end of your model's getSessionData... Code: return $query; Oops! RE: Session system - InsiteFX - 01-19-2018 You need to return the result of the query from your model. Also have you loaded the database? RE: Session system - florent6001 - 01-19-2018 Yes the database is loaded. The return query is for get pass the $query to the controller? New problem: A PHP Error was encountered Severity: Notice Message: session_write_close(): Skipping numeric key 0 Filename: Unknown Line Number: 0 Backtrace: Controller: Code: public function login(){ Model: Code: public function getSessionData($username){ |