Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

Simple IF problem

Recommended Posts

Hii,
I'm slightly confused why my IF statement doesn't work :/
Basicalyl i have a MOD CP, and Only allowing Admins and
Mods to access it, So i used the normal RANK IF statement

Problem is i set the statement to be if rank is NOT admin or
Mod then error, yet it will error me saying i'm not the correct rank

my code:
[code=php:0]if($rank != "mod" || $rank != "admin"){
echo "you're not authorized";
exit();
}[/code]

Share this post


Link to post
Share on other sites
Where is it in your script. It looks fine but placement of it may be a factor.

Ray

Share this post


Link to post
Share on other sites
well the thing is it works fine as...
if( $rank != "admin" ){
...
}

Then i added - || $rank == "mod" etc..

Share this post


Link to post
Share on other sites
A conclusiong, As there is three ranks, ADMIN - MOD -USER, if i set it to
if( $rank == "user" ){
//error
}

would it be secure?

Share this post


Link to post
Share on other sites
I find that is just a logic problem...

try this:
[code]
<?php
if($rank != "mod" && $rank != "admin"){
echo "you're not authorized";
exit();
}
?>
[/code]

Share this post


Link to post
Share on other sites
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]
<?php
if (($rank == "mod") || ($rank == "admin")){
  echo "You're authorized";
}
else {
  echo "You're not authorized";
  exit();
}
?>[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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.

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.