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
https://forums.phpfreaks.com/topic/232249-user-privileges/
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
https://forums.phpfreaks.com/topic/232249-user-privileges/#findComment-1194767
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.