CodeIgniter Forums
Admin directory - 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: Admin directory (/showthread.php?tid=25290)

Pages: 1 2


Admin directory - El Forum - 12-07-2009

[eluser]WebbHelp[/eluser]
Hi!

I got a directory there I only got the admin files.
I want to check if the admin is logged in, and got permission to see the pages.

Do i need to check it in every function in the class?

Thanks //Webbhelp


Admin directory - El Forum - 12-07-2009

[eluser]Ben Edmunds[/eluser]
You can use a constructor. Constructors are ran when the class is instantiated.

If your on PHP4 then create a method with the same name as the class and then put your code into this method to check the users authentication. If your on PHP5 create a method named __construct and then put your code into this method to check the users authentication.


Admin directory - El Forum - 12-07-2009

[eluser]WebbHelp[/eluser]
Yes maybe ,that seems to be a good idé.
But, in codeigniter index, is running first, can i write in in that function to?

And if the visitor don't have permisson the the site, what can I do then, so the other functions can't be runned?

Thanks


Admin directory - El Forum - 12-07-2009

[eluser]Ben Edmunds[/eluser]
Just check for the proper creds in the constructor and if they shouldn't be there redirect them to the page they should be at.


Admin directory - El Forum - 12-07-2009

[eluser]WebbHelp[/eluser]
Yes, that is a smart and a simple way, I like it, thanks Smile

Just a question, is it possible in a easy way to give them a message and deny them from the other function?

Thank you so much for helping me Smile


Admin directory - El Forum - 12-07-2009

[eluser]Ben Edmunds[/eluser]
What I usually do is set a message in flashdata.


Admin directory - El Forum - 12-09-2009

[eluser]WebbHelp[/eluser]
Sorry, but what do you mean?

Thanks Smile


Admin directory - El Forum - 12-09-2009

[eluser]Ben Edmunds[/eluser]
Before your redirect:
Code:
$this->session->set_flashdata(''message', 'You were redirected because...');
redirect();

and then at the page you redirected to you can access the message with:
Code:
$this->session->flashdata('message');



Admin directory - El Forum - 12-09-2009

[eluser]WebbHelp[/eluser]
Aha, Now I understans sry Smile

Thank you very much for reply, this is helping me much!

Btw, What do you recommended: use PHP standard sessions or Codeigniters session-class?

Thanks Smile


Admin directory - El Forum - 12-09-2009

[eluser]Ben Edmunds[/eluser]
I use both depending on my needs.

The CI session library is good but use whichever suits your needs best.