Results 1 to 5 of 5

Thread: Sessions and admin/users

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139

    Sessions and admin/users

    Hi,

    I'm using sessions for a members area of the website but when a users has logged in how do i work out if the user is a admin or a user???



    I'm using a mysql database!!

  2. #2
    Hyperactive Member Sgt-Peppa's Avatar
    Join Date
    Mar 2003
    Location
    Munich - Germany
    Posts
    476
    Why dont you just store the permission along with the user name in a table? Create a table permissions, for example with 1 Administrator, 2 User, 3 Superuser whatever diffrences you make, and assign every user the matching permision.

    Dont know if thats the correct way but it works.

    HTH, Stephan
    Keep Smiling - even if its hard
    Frankie Says Relax, wossname Says Yeah!
    wossname:--Currently I'm wearing a gimp suit and a parachute.
    C# - Base64 Blog

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2003
    Location
    Auckland
    Posts
    1,139
    yip i have that but when a page loads after they log on how does it work out with the sessions if the person is an admin or user??

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by kiwis
    yip i have that but when a page loads after they log on how does it work out with the sessions if the person is an admin or user??
    You can have another session variable that contains the administration level of the user. Then, depeding upon the value of that, you perform different actions, show/hide different links.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Maybe I'm not understanding the problem...but can't you use the session username to search the table and find the permission field for that user?

    Code:
    $users = mysql_query("SELECT * FROM userTable WHERE username='" . $_SESSION['username'] . "'") or die(mysql_error());
    
    if ($user = mysql_fetch_array($users)) {
        //validate user (password and such)
        //get user permission ($user['permission'] or something)
    } else {
        //invalid session information
    }
    That's how I'd do it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width