Jump to content


Photo

Simple IF problem


  • Please log in to reply
8 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 25 September 2006 - 07:21 PM

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:
if($rank != "mod" || $rank != "admin"){
echo "you're not authorized";
exit();
}


#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 25 September 2006 - 07:27 PM

Where is it in your script. It looks fine but placement of it may be a factor.

Ray

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 25 September 2006 - 07:33 PM

well the thing is it works fine as...
if( $rank != "admin" ){
...
}

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

#4 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 25 September 2006 - 07:37 PM

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

would it be secure?

#5 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 25 September 2006 - 07:53 PM

I find that is just a logic problem...

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


Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#6 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 25 September 2006 - 08:00 PM

Try to think why use && instead of ||
Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 26 September 2006 - 12:00 AM

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

<?php
if (($rank == "mod") || ($rank == "admin")){
   echo "You're authorized";
}
else {
   echo "You're not authorized";
   exit();
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 26 September 2006 - 12:21 AM

is $rank set to a while loop i dont see it any where?

example

<?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();
}
 }
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 26 September 2006 - 12:26 AM

is $rank set to a while loop i dont see it any where?


I think that bit's irrelevant at the moment.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users