Welcome Guest, Not a member yet? Register   Sign In
Admin directory
#1

[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
#2

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

[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
#4

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

[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
#6

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

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

Thanks Smile
#8

[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');
#9

[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
#10

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

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




Theme © iAndrew 2016 - Forum software by © MyBB