Welcome Guest, Not a member yet? Register   Sign In
Check if user exists on page load
#1

[eluser]Constantin Iliescu[/eluser]
Hello!
I'm developing an membership system (based on tutorials, of course :-) ) and hit a wall... I'm saving the user id in a session variable and I want to check at each page load if that user id really exists, so I can update the 'login box' links. I have no idea how to to this...
Can somebody help me with this?
Thanks!
#2

[eluser]Ben Edmunds[/eluser]
How are you saving it? In session?

If you use a MY_Controller you can just check it in the constructor of the MY_Controller.
#3

[eluser]Constantin Iliescu[/eluser]
Wow! That was fast! :-) Yes, I'm saving the id in a session variable. And thanks for reminding me of the MY_Controller which in fact, already is in my site... Again, from a tutorial Big Grin. Thanks again, Ben! That was my first silly post... More to come Smile
#4

[eluser]mvdg27[/eluser]
Another suggestion would be to have your check inside a library and autoload it, so it get's automatically checked upon each page request. I think that's the way I usually go about this. Hope that helps.
#5

[eluser]stuffradio[/eluser]
[quote author="mvdg27" date="1261188886"]Another suggestion would be to have your check inside a library and autoload it, so it get's automatically checked upon each page request. I think that's the way I usually go about this. Hope that helps.[/quote]

That already happens automatically if you use MY_Controller.
#6

[eluser]Constantin Iliescu[/eluser]
Yep, in MY_Controller I load the user_model and check if the user_id from the session variable really exists in my database. If not, I destroy the session. Then, I extend MY_Controller with all my other controllers.
Thanks, guys! Big Grin
#7

[eluser]mvdg27[/eluser]
[quote author="stuffradio" date="1261216063"][quote author="mvdg27" date="1261188886"]Another suggestion would be to have your check inside a library and autoload it, so it get's automatically checked upon each page request. I think that's the way I usually go about this. Hope that helps.[/quote]

That already happens automatically if you use MY_Controller.[/quote]

I wasn't arguing that using MY_Controller wouldn't work, I know it does. I just wanted to share a different way to achieve the same goal Smile ... I myself prefer the autoloaded library over using MY_Controller. Whichever is better or faster, I'll leave to the real CI experts.

Cheers, Michiel




Theme © iAndrew 2016 - Forum software by © MyBB