Page 1 of 1
what's going on here?
Posted: Wed Sep 10, 2003 10:02 pm
by m3rajk
ok. i don't get this....
i have some access checks that look like
Code: Select all
# if you're access level 1, 2, or 3
if($sa!=($al1||$al2||$al3)){
but then i had a check that was failing that was looking for an either or to figure out what to do to a user, so i realized it was only letting me through as a quirk (or so i thought).
but now i hae another issue. in a few functions i switched the above to
Code: Select all
if(($sa!=$al1)||($sa!=$al2)||($sa!=$al3)){
and now it doesn't work, even though i know for a fact my access levelis one of the ones there (access levels are in a db include that i KNOW is included in the function. $sa is set previously when it finds the users' SiteAccess)
i don't get what's going on here. is the first way valid? why doesn't the second work?
i even echoed out the if line to see that i did truely match one fo the values.
Posted: Wed Sep 10, 2003 10:22 pm
by trollll
The second uses an assignment operator instead of a comparison operator. Just need to add another "=" in each test. Did the first one block you if you didn't meet the access level?
Posted: Wed Sep 10, 2003 10:29 pm
by JAM
That is the most annoying error, I myself also manages to do from time to time. Kinda tricky as it doesn't usually generate any kind of error.
Both the first and the second has the same error:
Code: Select all
if($sa=($al1||$al2||$al3)){
// assigning $sa with... $al1 or $al2 or $al3
if(($sa=$al1)||($sa=$al2)||($sa=$al3)){
// assigning $sa with $al3
Posted: Thu Sep 11, 2003 2:15 pm
by m3rajk
my apologies to those that looked already, when i sent it to myself, it lost the ! in front of the = it was suppossed to be !=
sorry for the confusion
Posted: Thu Sep 11, 2003 2:38 pm
by JAM
I think you should look more at the usage of ||'s (or) and &&'s (and).
You are thinking right, if you where to use == instead of != comparing the two.
Code: Select all
if($sa==($al1||$al2||$al3)){
// or
if(($sa==$al1)||($sa==$al2)||($sa==$al3)){
Posted: Thu Sep 11, 2003 10:26 pm
by m3rajk
so it only should work with the == sets and not the !=?
i ask because of this....
ripped form another forums wrote:Okay then... I *think* you should be using the cookie or session variables there. Unless you have $sa = $_COOKIE[sa]; or something?
Also, while this is awfully vague, I found I had to be really careful to get all the information in the right order. I didn't use variables for the check, but rather actual things.
So:
PHP:--------------------------------------------------------------------------------
if ($_SESSION[adminaccess] != ('admin'||'moderator')) {}
--------------------------------------------------------------------------------
Check to make sure your $a1 et cetera variables make sense, too. (I'm not saying you can't use variables, I don't know.) And make sure that $sa is really being passed along in the cookie or session by doing this:
PHP:--------------------------------------------------------------------------------
if (isset($sa)) {
echo $sa;
exit;
}
--------------------------------------------------------------------------------
And then you'll know for sure.
and my response to her:
actually i pull it out of the db at the begining of each function when i double check everyone is authorized (by username and pw which is in cookies)
and i already echoed out to make sure that
1: $sa is being set right
2: the variables i check against are set right
and i found in all instances that they were, php was just being funky about letting me through. in some cases it acted as if if($sa==($jra||$adm||$wbm)) correctly, in other times it didn't (the check to see if you can do that function does == and theone to see which level you have within the function is !=)
so i don't understand why it seems to work sometimes (most of the ==) and not others (some of the == and all of the !=) and when i change it to (($sa==$jra)||($sa==$adm)||($sa==$wbm)) is echos out right yet tells me i don't have access, and when i switch that back i have to mae the other one (== or !=) to be individual to work right (instead of just doing the first one regaurdless of if that's right)
Posted: Fri Sep 12, 2003 1:07 pm
by JAM
I have no straight answer to why it works only now and then... You could also ignore the and/or idea, and go straight for a;
Code: Select all
$allowed = array('foo', 'bar', 'kittythrow');
if (in_array($sa, $allowed)) {
// present
} else {
// not present
}
Posted: Fri Sep 12, 2003 11:40 pm
by m3rajk
JAM: the meaning of your last post went over me at first. i was looking at it just now after taking a bit of a brake for most of the day just to hope to get a clear picture. i realized that what was happening was that if one was true it'd work, whcih explains why it was happening... but then there's the inconsistency. upon further inspection i saw the cause of that.. some of the inital access checks were
which made it look like it was inconsistent.