Sir Jos Posted January 18, 2010 Share Posted January 18, 2010 Hi all, I have a mysql table with the following columns 1. privilege 2. applicationPath 3. code A number of rows are selected when i query using mysql_fetch_assoc. However, how can i get all these values in each row of each column and assign them into session values that I can access and use in each of my pages. Is there any way out? NB: Am trying to develop an application that uses a single login for users with different access-levels for different applications. With one password that a user have, he/she can login into the application, and with the neccessary access-levels/privileges he/she can access parts of the different application. Quote Link to comment https://forums.phpfreaks.com/topic/188875-passing-a-query-result-into-a-session/ Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 You can of course do something as simple as: $_SESSION['privileges'] = $row['privilages']; $_SESSION['applicationPath'] = $row['applicationPath']; $_SESSION['code'] = $row['code']; And work from that code, What would be ideal is to create a function such as 'checkPrivilages' to read the session, and allow only parts of that application that are authorized. Quote Link to comment https://forums.phpfreaks.com/topic/188875-passing-a-query-result-into-a-session/#findComment-997201 Share on other sites More sharing options...
jtgraphic Posted January 18, 2010 Share Posted January 18, 2010 If you run a while through your results and dump them into an array, and then put that array into the session variable, you should be able to keep it. Quote Link to comment https://forums.phpfreaks.com/topic/188875-passing-a-query-result-into-a-session/#findComment-997202 Share on other sites More sharing options...
Sir Jos Posted January 18, 2010 Author Share Posted January 18, 2010 Thanks for the help i was able to do something like this: $unifiedUser = array(); $count = 0; if(mysql_num_rows($LoginRS_UnifiedUser) >= 1){ while($unifiedUser[] = mysql_fetch_assoc($LoginRS_UnifiedUser)){ $count++; } } $_SESSION['Details'] = $unifiedUser; But, please how can i access the individual values in the session value on the various pages. Quote Link to comment https://forums.phpfreaks.com/topic/188875-passing-a-query-result-into-a-session/#findComment-997228 Share on other sites More sharing options...
oni-kun Posted January 18, 2010 Share Posted January 18, 2010 But, please how can i access the individual values in the session value on the various pages. Add session_start(); , to the beginning of any page you want to access the sessions. Then you'll be able to access them like <?php session_start(); echo $_SESSION['Details']; //Will echo the session value defined in the other page ?> Sessions are serverside data that will remain until the cookie expires, it can be accessed anywhere that calls session_start(); Quote Link to comment https://forums.phpfreaks.com/topic/188875-passing-a-query-result-into-a-session/#findComment-997233 Share on other sites More sharing options...
jtgraphic Posted January 18, 2010 Share Posted January 18, 2010 You can access an individual row like this: $row_number = <number>; echo $_SESSION['Details'][$row_number] You can also SEE it by using this: echo "<pre>".print_r($_SESSION,true)."</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/188875-passing-a-query-result-into-a-session/#findComment-997236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.