Re: User Access (Limiting Access)

From: Date: Mon, 14 Apr 2003 16:00:41 +0000
Subject: Re: User Access (Limiting Access)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-143799@lists.php.net to get a copy of this message
I set a variable at the top of each page: $allow = x; // where x = 0, 1, 2, or 3 Then I include a small snippet that compares it to the group cookie set when they logged in. If their group number is bigger than allowed, they are kicked to their default page.:
    if ($_COOKIE['group']>$allow) {
        switch ($_COOKIE['group']) {
            case 1:
                header ("Location: /default1/");
                die;
                break;
            case 2:
                header ("Location: /default2/");
                die;
                break;
            case 3:
                header ("Location: /default3/");
                die;
        }
    }
If some pages allow 0, 1, 2, but I only want 0 and 1 to see certain text, I just add if ($_COOKIE['group']<2) { echo ...; } - John On 4/14/2003 9:07 AM, Jess Hunter wrote:
Well as I conitnue on my quest for understanding user authentication I am starting to grasp the concept. I have managed to set up a login screen that uses cookies and even figured out how to kill the session when the browser is shut down. Now comes my dilemma. Let's say I have several user types in a database (1,2,3,4,5) and I only want certain levels to have access to certain areas. Could someone either tell me or show me if this is possible and how to go about implementing it into my current script? Here is the validation part I am using now: <SNIPPET> $userInfo = mysql_query($sql); if($user = mysql_fetch_object($userInfo)) { setcookie(userID, "" . $Username); session_start(); session.cookie_lifetime; header("Location: $afterLoggedIn?user=" . $user->$useridField); } else { $error = "$errorMessage"; } </SNIPPET> Thanks in advance Jess


« previous php.general (#143799) next »