Author Topic: check user level script (not working  (Read 338 times)

0 Members and 1 Guest are viewing this topic.

Offline devangelTopic starter

  • Irregular
  • Posts: 7
    • View Profile
check user level script (not working
« on: March 17, 2010, 04:49:02 PM »
hey guys,

im making a check user level script.

if $usr['authlevel']>4
 echo "adminpanel"

i have set my sessions.

         $_SESSION['SESS_USERID'] = $user['userid'];
         $_SESSION['SESS_USERNAME'] = $user['username'];

how do i use the sess_userid to retrieve the users details for the users id only.

ive tried ::

 mysql_query("SELECT * FROM users WHERE userid = '$userid'") or die(mysql_error());
$usr = mysql_fetch_array( $data );

please someone with guidance, ive been searching for hours. i need to make a if statement to check user level, but i havent managed to retrieve db info via session.


Offline schilly

  • Devotee
  • Posts: 870
  • Gender: Male
    • View Profile
    • Damn Semicolon
Re: check user level script (not working
« Reply #1 on: March 17, 2010, 05:06:46 PM »
well you could store the user level in your session when you login then you wouldn't need to query the db.

then you can do something like:
if ($_SESSION['authlevel']>4)
 echo 
"adminpanel";


Offline devangelTopic starter

  • Irregular
  • Posts: 7
    • View Profile
Re: check user level script (not working
« Reply #2 on: March 17, 2010, 05:20:52 PM »
how would i be able to save the authlevel in a session

ive tried

         $user = mysql_fetch_assoc($result);
         $_SESSION['SESS_USERID'] = $user['userid'];
         $_SESSION['SESS_USERNAME'] = $user['username'];
         $_SESSION['SESS_AUTHLEVEL'] = $user['authlevel'];

how would you define it into a session?

Offline schilly

  • Devotee
  • Posts: 870
  • Gender: Male
    • View Profile
    • Damn Semicolon
Re: check user level script (not working
« Reply #3 on: March 17, 2010, 05:29:22 PM »
that looks fine to me. make sure your query is actually returning the authlevel column.

Offline devangelTopic starter

  • Irregular
  • Posts: 7
    • View Profile
Re: check user level script (not working
« Reply #4 on: March 17, 2010, 05:32:56 PM »
my query doesnt look wrong

   $qry="SELECT * FROM users WHERE username='$username' AND password='".md5($_POST['password'])."' and authlevel>0";
   $result=mysql_query($qry);

it checks to see if your banned userlevel (0)

but yeah i cant figure out why its saying its not defined i used:

<?php if ($_SESSION['authlevel']>4)
 echo "adminpanel"; ?>

and i got

Notice: Undefined index: authlevel in

on that line.