Page 1 of 1

Question about Protect page with session

Posted: Sat Jun 02, 2012 3:14 pm
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

Re: Question about Protect page with session

Posted: Sat Jun 02, 2012 6:11 pm
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');
}

Re: Question about Protect page with session

Posted: Sat Jun 02, 2012 10:11 pm
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 :)

Re: Question about Protect page with session

Posted: Sun Jun 03, 2012 12:04 am
by Temor
That is a much nicer way of doing it :)

Re: Question about Protect page with session

Posted: Sun Jun 03, 2012 5:15 am
by drama22
WOW Thankkkkkkks ,,, this is the best forum ever , Thanks for your help guy's :D :D :D

Re: Question about Protect page with session

Posted: Sun Jun 03, 2012 8:04 pm
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