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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.