Jump to content

user privileges


freemancomputer

Recommended Posts

I am attempting to have some links show up on my page only if a user is an admin. The way I have the user data base is user name password and rank. rank is a 1 or 2, 2 for admin. This is what I have right now as a test bed, I think the rank variable is not being passed properly but I'm not sure.

 

Thanks in advance.

 

This is what i have for the log in page

<?php
//connection stuff

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


$count=mysql_num_rows($result);
$rank=mysql_num_rows('rank');


if($count==1){
session_start(); 
$_SESSION['login'] = "1"; 
$_SESSION['rank'] = $rank;
header ("Location:index.php");
} else { 
$errorMessage = "Invalid Login"; 
session_start(); 
$_SESSION['login'] = '';
} 
?>

 

This is the header that will be on every page to keep the session.

<?php ini_set ("display_errors", "1");
error_reporting(E_ALL);
?>
<?php
session_start();
if(!$_SESSION['login']){
$_SESSION['rank'];
header("location:login.php");
}
?>

<?php
$rank=$_SESSION['rank'];
?>

 

And this is what I have to show the link.

<?php
if($rank<=2){
?>
<tr>
<td><span class="nav"><a href="link">link</a></span><br /></td>
</tr>
<?php
}
?>

Link to comment
Share on other sites

$rank=mysql_num_rows('rank');

 

That's where your issue is.

 

perhaps:

 

$row = mysql_fetch_assoc($result);
    $rank = $row['rank'];

 

EDIT:

 

if($rank<=2){

 

From what you've stated then any user below admin rank will see this link.

 

if you want admin only then:

 

if($rank == 2) {

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.