if else multiple times?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

if else multiple times?

Post by ianhull »

Is it possible to use if else statements multiple times?

What I mean is


if ($usrlevel == $adminlevel){
do something
if not does it match userlevel
if not redirect to unauthorized.php

If anyone has any advice on this it would be much appreciated.
or even another way to have user levels in my system.

Thanks
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

looks like you are struggling for a basic if..elseif...else statement

Code: Select all

if (condition1){
}elseif(condition2){
}else{
header(Location: file.php);
}
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Yeah I am struggling a bit lol,

thanks for this.

Can this go on for a while?

i.e.

Code: Select all

if (condition1){ 
}elseif(condition2){
}elseif(condition3){
}elseif(condition4){
}else{ 
header(Location: file.php); 
}
etc?
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Code: Select all

if (condition1){ 
}elseif(condition2){ 
}elseif(condition3){ 
}elseif(condition4){ 
}else{ 
header(Location: file.php); 
}
if you are asking whether the above would work...yes
if php can execute one thing like if..elseif..else then it also should be able to execute if..elseif..elseif...else as well :wink:
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Thats cool,

Thank you very much.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

You might also want to look at switch()
Post Reply