Jump to content

Permissions help


9antsim

Recommended Posts

I am trying to sort out permissions for when the user logins in so if there friend or family they will switch to a different userpanel but i have tried this:

 

<?php
$conn = mysql_connect('BLANK', 'BLANK', 'BLANK') or die(mysql_error());
mysql_select_db('BLANK', $conn);
// Start session
session_start(); 

// Check if user is logged in
if(isset($_SESSION['user_id'])) {
// User is logged in!
$query = mysql_query("SELECT username FROM login
			   WHERE ID = " . $_SESSION['user_id'] )
			   or die(mysql_error());

list($username) = mysql_fetch_row($query);

echo 'Hi '. $username . ', welcome to your profile!';

} else {

// User not logged in
echo 'Please login before opening the user panel.';

}

// This allows me to change the content the person will see
if($_SESSION['rank'] == "friend")
{
echo include "friendpanel.php";
}
if($_SESSION['rank'] == "admin")
{
echo include "admincontrol.php";
}
?>

 

Can anyone see whats wrong with it?

Link to comment
https://forums.phpfreaks.com/topic/109382-permissions-help/
Share on other sites

it grabs the $username and thats all. the problem is here. There is no $_SESSION['rank'] so none of that code is ever executed. Maybe in your DB you can store the username along with who that person is ie: admin,friend

then you grab that value and store it in a variable such as $who then we can do:

 

if($who == "friend")

{

echo include "friendpanel.php";

}

if($who == "admin")

{

echo include "admincontrol.php";

}

Link to comment
https://forums.phpfreaks.com/topic/109382-permissions-help/#findComment-561079
Share on other sites

I made a field in my DB called rank so the person could automacially decide if they want them to have certain rights,

 

i added a session of the rank above the two options which it would bring up the correct usercontrol for them, but i haven't define what $_SESSION = [rank] is so all it knows is that [rank] equals a session. I hope that actually made sense? I have stripped all the rank out and going to start again to add it in so i don't mess up my login script so far

Link to comment
https://forums.phpfreaks.com/topic/109382-permissions-help/#findComment-561085
Share on other sites

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.