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

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.