Welcome Guest, Not a member yet? Register   Sign In
Session best practice question
#1

[eluser]maadmac[/eluser]
How do you normally direct logged in users? My initial inclination would be something like this:

Code:
<?php if ($this->session->userdata['logged_in'] == true) redirect('/somewhere'); ?>

at the top of each page. But I'm running into a 'headers sent' issue, and so I'm wondering if I should try to address it via ob_flush or move the code somewhere else on the page, so the headers get sent first, or something else? Any tips are appreciated, thanks.
#2

[eluser]Rick Jolly[/eluser]
I'd put that in the controller constructors instead of in the view. To avoid repetition, you could create an application/base controller with that code in its constructor and extend it for all pages that require a login.
#3

[eluser]maadmac[/eluser]
[quote author="Rick Jolly" date="1193438518"]I'd put that in the controller constructors instead of in the view. To avoid repetition, you could create an application/base controller with that code in its constructor and extend it for all pages that require a login.[/quote]

Hi Rick,

That makes sense, thanks. And sorry if this is a noob question, but would you mind clarifying what you mean by creating and extending a base controller?

Thanks!
#4

[eluser]E1M2[/eluser]
touched on here
#5

[eluser]maadmac[/eluser]
Perfect, thanks E1M2.




Theme © iAndrew 2016 - Forum software by © MyBB