Question about Protect page with session

Ask about a PHP problem here.
Post Reply
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Question about Protect page with session

Post by drama22 »

hello guys , iam trying to protect some pages on my script, i want control on session who can show this page i make somthing but after i check i see that's works with 1 name only i want make it allow to many name here is example to be more clear
$pro = $user_data['username'];
if ($pro != "drama", "another name", "another one") {
	die ('You are not allowed to use this page');
}
if i make only one name it works normal but if i make to many names i get page error any thing to fix this ? :D
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Question about Protect page with session

Post by Temor »

I would put the accepted names in an array and see if $pro is in that array. Like this:
$pro = "drama";
$accepted = array(
'First'=> 'drama',
'Second' => 'another name',
'Third' => 'another one'
);
if (in_array($pro, $accepted) === false) {
        die ('You are not allowed to use this page');
}
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Question about Protect page with session

Post by jacek »

You can also inline it like this
if (in_array($pro, array("drama", "another name", "another one")) == false){
    // redirect ?
}
I use that all the time :)
Image
User avatar
Temor
Posts: 1186
Joined: Thu May 05, 2011 8:04 pm

Re: Question about Protect page with session

Post by Temor »

That is a much nicer way of doing it :)
drama22
Posts: 22
Joined: Wed May 30, 2012 9:40 am

Re: Question about Protect page with session

Post by drama22 »

WOW Thankkkkkkks ,,, this is the best forum ever , Thanks for your help guy's :D :D :D
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Question about Protect page with session

Post by jacek »

drama22 wrote:WOW Thankkkkkkks ,,, this is the best forum ever , Thanks for your help guy's :D :D :D
:D :D Thanks for being nice. :D :D
Image
Post Reply