Jump to content

Passing a query result into a session


Sir Jos

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/188875-passing-a-query-result-into-a-session/
Share on other sites

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.

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.