PHP & Bitwise as access control

I am using bitwise as access control for pages in a script.

In user table there is a page_access column. In menu table there is a permid column.

4 pages in menu table (and permid):

[ul][li]map 1[/li]
[li]import 2[/li]
[li]users 4[/li]
[li]testing 8[/li][/ul]

I then use mysql to pull menu… (getuserdets($liuid,‘page_access’) - returns logged in users page_access from mysql)

$sql = "SELECT name,page FROM menu WHERE permid & ".getuserdets($liuid,'page_access');

This works perfectly.

However the equivalent in PHP does not appear to, using the following:

[php]$sql = “SELECT name,page,permid FROM menu ORDER BY permid”;
$res = mysqli_query($mysqli,$sql);
while($row = mysqli_fetch_row($res)) {
$checked = ‘’;
if ($row[2] & getuserdets($_REQUEST[‘id’],‘page_access’)) { $checked = ‘checked’; }
$access .= $row[2]." – “.getuserdets($_REQUEST[‘id’],‘page_access’).” $checked
";
<< SNIP FORM CHECKBOXES >>
}[/php]

This seems to display incorrectly ($access is a temp var to show this) from 2 separate users, one works as expected the other does not…

[code]
All should be checked - (wrong)
1 – 15 checked
2 – 15
4 – 15
8 – 15

Two checked - (correct)
1 – 3 checked
2 – 3 checked
4 – 3
8 – 3 [/code]

Can’t see the difference in PHP code to MySQL query and all 4 pages are returned as expected for a permid of 15

in your sql code there is a WHERE clause …

[php]$sql = "SELECT name,page FROM menu WHERE permid & ".getuserdets($liuid,‘page_access’);[/php]

i dont see the where clause in your php …

[php]$sql = “SELECT name,page,permid FROM menu ORDER BY permid”;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service