Welcome Guest, Not a member yet? Register   Sign In
User Authentication - Placement of code?
#11

[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).
#12

[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();
$this->load->view('home_view');
The session is destroyed and the user is shown the home page once the session is destroyed. The link that I have is this:
Code:
// 'login' is the class (it's also the file name) and logout is the function as per the user guide
anchor('login/logout', 'Logout');
However this is not working. Perhaps I just don't understand how CI handles URL's.

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!
#13

[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
#14

[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?
#15

[eluser]ekeretex[/eluser]
Did you echo the link?
Code:
echo anchor('login/logout', 'Logout');
#16

[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.
#17

[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?
#18

[eluser]RyanH[/eluser]
Does anybody have any advice? Thanks.
#19

[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.
#20

[eluser]Crimp[/eluser]
RyanH:

Simply don't load sessions for the controllers where no login or use of session data is needed.




Theme © iAndrew 2016 - Forum software by © MyBB