Jump to content

Session permissions: giving the user permission when they log in


wtfsmd

Recommended Posts

Hey guys, im trying to figure out why i can't get this to work  :-\

here is what i need help with:  I am trying to make the session get the userrank for whom ever is logged in, regular people have the rank of 1, admins have the rank of 2. currently my userrank Session is not working most likely because of a error.

i cut out most of the code, this is just the stuff i thought would be important.

[code]

<?php
//start session
session_start();
//include the database login
require 'login/db_connect.php';


//make a connection to the database
$sql = "SELECT username, password, userrank FROM users WHERE username = '".$_POST['uname']."'";

$result = mysql_query($sql) or die(mysql_error());

$row = mysql_fetch_array($result) or die(mysql_error());

// where $row is the record pulled from the database.
$_SESSION['level'] = $row['userrank'];

?>
[/code]

on the page that i want admin privileges on i have this:
[code]

<?php
                 

include('fetchnews.php');
print_r($_SESSION);
//session user id
if($_SESSION['level'] == "2") {
include('test.php');


} else {

}

?>
[/code]

I have print_r($_SESSION), and what i get is this:
[quote]

Array ( [username] => Admin [password] => d159167596fd8ac07a8c9cf92150848d [level] => )
[/quote]

Here is a screenshot of my database table [url=http://tinypic.com/2z7mkie.png]http://tinypic.com/2z7mkie.png[/url]

Any help would be appreciated, i most likely did this wrong lol.
What's the output of a print_r($row) on your first page? Make sure the $row['userrank'] value is actually getting set right. Then you will know if it is either the MySQL query or the session that is bad.

Brandon C.
Okay, i fixed it i took out
[code]
$row = mysql_fetch_array($result) or die(mysql_error());
[/code]

and i put in this further down the page
[code]
$result = mysql_query("SELECT userrank FROM users WHERE username = '".$_POST['uname']."'")
or die(mysql_error());

$row = mysql_fetch_array( $result) or die (mysql_error());
[/code]

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.