Jump to content

Adding diffrent uer levels to a page


freemancomputer

Recommended Posts

I just added a user log on for a site I am building using PHP.  I used a simple session based system for this. I can log on just fine. What I am looking for is a way to pass on in ht session what rank a user is so some links/pages will only show for the admin or the super user but not the normal user. I rank the users as Admin 1, superuser 2, and user 3.

 

This is what I have for the session in my header that allows you to be logged in.

<?
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
?>

 

Here is what I have that starts the session


//Connection stuff

$query="SELECT * FROM user WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($query);

$count=mysql_num_rows($result);

if($count==1){

session_register("myusername");
session_register("mypassword");
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}

ob_end_flush();
?>

Link to comment
https://forums.phpfreaks.com/topic/231921-adding-diffrent-uer-levels-to-a-page/
Share on other sites

Firstly, session_register & session_is_registered have long been deprecated and should no longer be used. You might want to check the manual in regards to how to use sessions.

 

As for your question, as you log your user in, simply store there user level (your already querying for all * a users information yet failing to use what is relevant) within the $_SESSION array and check it whenever required.

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.