page viewable only if logged in |
[eluser]josh48202[/eluser]
how would a make a page viewable if your logged in. i didnt have any luck looking for another topic maybe someone could point me in the right direction. thank you.
[eluser]Craig A Rodway[/eluser]
Search the forum for user authentication, login, authentication etc or have a look on the Wiki. There are already-made libraries that allow you to do this with varying levels of complexity or you could do it yourself using sessions.
[eluser]josh48202[/eluser]
thx i just found them i guess i should have kept looking. can someone please delete this topic.
[eluser]Pascal Kriete[/eluser]
Well there are lots of solutions to this. And there are plenty of libraries and such that people have written. If you do a search you'll likely find a few of them. This is what I usually do: I have a login controller that checks the login data in a model. If it matches I set a variable called logged_in in my session: Code: $this->session->set_userdata('logged_in', TRUE); Then I have a little helper that I wrote which contains the following: Code: // Checks if logged in and redirects to $redirect if false So now, in the constructor for my login controller (called login) I put: Code: $this->load->helper('login'); And on any controller/function I want to protect I put: Code: $this->load->helper('login'); And there you go. EDIT: Seems I was a little too slow ![]()
[eluser]josh48202[/eluser]
maybe i should explain this better. i want to add a tab to the navigation that can only be seen if your logged in.
[eluser]Pascal Kriete[/eluser]
Ok, well assuming you're using the code I posted you would put this in your controller: Code: $this->load->helper('login'); And then in your view you would do: Code: <?php if (isLoggedIn()) : ?> Hope that helps,
[eluser]josh48202[/eluser]
well im using FAL and i got it to where you have to be logged in to see the page so i have this Code: $this->freakauth_light->check('user');
[eluser]Pascal Kriete[/eluser]
I've never used FAL, but according to their documentation, you could use this: Code: $this->freakauth_light->isValidUser(); Which will return true if the user is logged in. So basically do this in your controller: Code: $data['logged_in'] = $this->freakauth_light->isValidUser(); And in your view you put: Code: <?php if ($logged_in): ?>
[eluser]josh48202[/eluser]
well im trying to do this with the tab. i added the code to the controller and i added the rest of the code to the view file and im getting an error. this is what my view file looks like. its for the menu tabs. Code: <?php $ci_uri = trim($this->uri->uri_string(), '/'); $att = ' id="active"';?>
[eluser]Pascal Kriete[/eluser]
Hmm, I don't see any mistakes in your code. Is it a specific error? Does it work without the if statement? Otherwise I must say I'm out of ideas ![]() |
Welcome Guest, Not a member yet? Register Sign In |