Re[2]: [PHP] newbie: help with array

From: Date: Mon, 28 Apr 2003 13:39:38 +0000
Subject: Re[2]: [PHP] newbie: help with array
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-145525@lists.php.net to get a copy of this message
Hi, Monday, April 28, 2003, 11:14:30 PM, you wrote: p> The check permission only works when the permission is in the array. When p> the array does not contain the required permission the following error is p> thrown: p> Notice: Undefined offset: 3 in C:\Inetpub\...\menu.php on line 29 p> Any ideas what may be casuing this? Thanks for your help so far. p> "Marek Kilimajer" <kilimajer@webglobe.sk> wrote in message p> news:3EAD0B3E.9050901@webglobe.sk... >> Something like: >> // set permissions >> while($perm = mysql_fetch_assoc($res)){ >> $_SESSION['userPermissions'][$perm['userPermission']]=1; >> } >> >> //check permission >> if($_SESSION['userPermissions']['read']) { >> //is allowed to read >> } >> >> patlebon wrote: >> >> >I have database table that contains userId and permissionId. I want to p> query >> >this table and make an array/list of permissions for a user when they p> login >> >and assign these to a session variable called p> $_SESSION["userPermissions"]. >> >On other pages i want to check if their $_SESSION["userPermissions"] p> array >> >contains certain permissions and only allow certian bits of code to be >> >displayed if it does. >> > >> >I have the query to get the permissions from the database but after this p> im >> >not sure what to do. >> > >> >Any help on how to do this would be much appreciated. >> > >> > >> > >> > >> > >> You should do the set like this: if(isset($_SESSION['userPermissions']['read']) && $_SESSION['userPermissions']['read'] == 1) { //is allowed to read } -- regards, Tom

« previous php.general (#145525) next »