User Authentication - Placement of code? |
[eluser]ekeretex[/eluser]
That's partly why I used this line in my code Code: $this->data['session_id'] = $this->session->userdata('session_id'); If you use the full string in the conditional it fails ( I have no idea why but I've learnt to work around it).
[eluser]RyanH[/eluser]
That makes sense. I'm attempting to test this but for whatever reason, I can't get a few things to work before I can test this. The first being I can't get the logout link to work. I've read the user guide for URL's and I thought it made sense, but it's apparently not working. I created a logout function in the login controller file that does the following: Code: $this->session->sess_destroy(); Code: // 'login' is the class (it's also the file name) and logout is the function as per the user guide Secondly, it seems as if each page I go to while I'm "logged in", a new session is created. Any particular reason? Anyway to fix this? Thank you for your help!
[eluser]ekeretex[/eluser]
After destroying the session, it's best to redirect to a new page rather than load a view because the session is not killed on the page you call the session_destroy. I have had a lot of issues with the CI session library in the past and have given up on it. I currently use OBSession
[eluser]RyanH[/eluser]
Thanks, I'll take a look at that and see what I can do. Did you have any advice for the links?
[eluser]ekeretex[/eluser]
Did you echo the link? Code: echo anchor('login/logout', 'Logout');
[eluser]RyanH[/eluser]
Yes. The link is there, but it doesn't do anything. Is my link correct? login being the class name and logout being the function within that class.
[eluser]RyanH[/eluser]
I just noticed another problem that I seem to be having. It appears that a session is being created every time a person visits the site. I only want sessions to be created when someone logs in, and then destroyed when the person logs out. Secondly, I tried the OBSession library and nothing was being stored in the database. I updated the database table, the config file and over wrote the Session.php in the library folder. Anything I'm missing?
[eluser]Kemik[/eluser]
The CI session library creates a session for everyone. There's no way around this. You could add a line to the session (such as user_id) when the user logs in then check for that data when checking if the user is logged in.
[eluser]Crimp[/eluser]
RyanH: Simply don't load sessions for the controllers where no login or use of session data is needed. |
Welcome Guest, Not a member yet? Register Sign In |