Page 1 of 1

Arrays with if statements

Posted: Sat May 28, 2011 1:13 am
by Pazuzu156
In my CMS site, there is an admin section of the site. I am an admin, but I want more than one username to be an admin, how would i do this by adding multiple users into an array for administrator based on if they are set to admin in the database.

here is what I have as far as setting admin status:

Code: Select all

if($_SESSION['user']=='Administrator') {
	echo '<p align="center">| <a href="admin/">Admin</a> |</p>';
}
I want to keep that structure of the admin link based on if the user logged in is an admin, but using an array instead of just the username itself.

Re: Arrays with if statements

Posted: Sat May 28, 2011 1:23 pm
by amargharat
You can modify your script as follows;

Code: Select all

if(in_array($_SESSION['user'], $array_of_usernames)) {
        echo '<p align="center">| <a href="admin/">Admin</a> |</p>';
}

Re: Arrays with if statements

Posted: Sat May 28, 2011 2:34 pm
by Pazuzu156
Thanks man. Works :)