xyn Posted September 25, 2006 Share Posted September 25, 2006 Hii,I'm slightly confused why my IF statement doesn't work :/Basicalyl i have a MOD CP, and Only allowing Admins andMods to access it, So i used the normal RANK IF statementProblem is i set the statement to be if rank is NOT admin orMod then error, yet it will error me saying i'm not the correct rankmy code:[code=php:0]if($rank != "mod" || $rank != "admin"){echo "you're not authorized";exit();}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/ Share on other sites More sharing options...
craygo Posted September 25, 2006 Share Posted September 25, 2006 Where is it in your script. It looks fine but placement of it may be a factor.Ray Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98467 Share on other sites More sharing options...
xyn Posted September 25, 2006 Author Share Posted September 25, 2006 well the thing is it works fine as...if( $rank != "admin" ){...}Then i added - || $rank == "mod" etc.. Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98471 Share on other sites More sharing options...
xyn Posted September 25, 2006 Author Share Posted September 25, 2006 A conclusiong, As there is three ranks, ADMIN - MOD -USER, if i set it toif( $rank == "user" ){//error}would it be secure? Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98477 Share on other sites More sharing options...
eric1235711 Posted September 25, 2006 Share Posted September 25, 2006 I find that is just a logic problem...try this:[code]<?phpif($rank != "mod" && $rank != "admin"){echo "you're not authorized";exit();}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98495 Share on other sites More sharing options...
eric1235711 Posted September 25, 2006 Share Posted September 25, 2006 Try to think why use && instead of || Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98499 Share on other sites More sharing options...
HuggieBear Posted September 26, 2006 Share Posted September 26, 2006 Two things...1) You can't use OR when testing for negativity. 2) Try seperating each section with parenthesis to make it a bit more readable[code]<?phpif (($rank == "mod") || ($rank == "admin")){ echo "You're authorized";}else { echo "You're not authorized"; exit();}?>[/code]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98634 Share on other sites More sharing options...
redarrow Posted September 26, 2006 Share Posted September 26, 2006 is $rank set to a while loop i dont see it any where?example[code]<?php//database connection$query="select * from rank where id='$id'";$result=mysql_query($query):while($record=mysql_fetch_assoc($result)){if (('".$record['rank'].'" == "mod") || ('".$record['rank']."' == "admin")){ echo "You're authorized";}else { echo "You're not authorized"; exit();} }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98642 Share on other sites More sharing options...
HuggieBear Posted September 26, 2006 Share Posted September 26, 2006 [quote author=redarrow link=topic=109459.msg441397#msg441397 date=1159230061]is $rank set to a while loop i dont see it any where?[/quote]I think that bit's irrelevant at the moment.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22020-simple-if-problem/#findComment-98644 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.