CodeIgniter Forums
Check if user exists on page load - 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: Check if user exists on page load (/showthread.php?tid=25636)



Check if user exists on page load - El Forum - 12-18-2009

[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!


Check if user exists on page load - El Forum - 12-18-2009

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


Check if user exists on page load - El Forum - 12-18-2009

[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


Check if user exists on page load - El Forum - 12-18-2009

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


Check if user exists on page load - El Forum - 12-18-2009

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


Check if user exists on page load - El Forum - 12-19-2009

[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


Check if user exists on page load - El Forum - 12-19-2009

[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