load certain page - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

load certain page

drksprklsdrksprkls Posts: 6Member
i want to make a login to protect certain areas of a site.
i want 3 different "user groups"

group one will have access to pages 1, 2, and 3
group two will have access to pages 1, 2, 3, and 4
and group three will have access to pages 1, 2, 3, 4, and 5

if i create these groups and usernames and passwords in a MySQL database would it be best to use an 'if, elseif, else' statement to determine which type of user is trying to access information or is there a better way?

also what is the code to load a certain page when an if statement returns true? ex: if ($a == $b){ #?#loadthispage#?#; } else { #?#loadthispage#?#; }
can't seem to find it.

Comments

  • tvientitvienti Posts: 230Member
    I would use binary operators create flags per page and per user. For example... the first bit indicates the first access level, second bit is the second access level, third bit is the third access level. Thus:

    Group one users will have an access level of 1 (0000 0001)
    Group two users will have an access level of 3 (0000 0011)
    Group three users will have an access of 7 (0000 0111)

    Then for each page, define an access level (1 - first bit, 2 - second bit, or 4 - third bit). Then you only need one if.

    [code]
    define (ACCESS_LOW, 1);
    define (ACCESS_MED, 2);
    define (ACCESS_HIGH, 4);

    /* let's pretend we're dynamically giving the user a
    group three access level, for testing purposes */
    $MyAccess = ACCESS_LOW & ACCESS_MED & ACCESS_HIGH;

    /* Later in the code, we want to see if he
    has access to a high level page */
    if ($MyAccess & ACCESS_HIGH)
    {
    // user has access to area
    }
    [/code]

    To load a page at a given point of code you can either use include/require, which will essentially stick all the code of the file into the current point of execution, or you can use a redirect (see: server-side redirects using Location: header and client-side redirects using Javascript, and meta tags)

    T

    : i want to make a login to protect certain areas of a site.
    : i want 3 different "user groups"
    :
    : group one will have access to pages 1, 2, and 3
    : group two will have access to pages 1, 2, 3, and 4
    : and group three will have access to pages 1, 2, 3, 4, and 5
    :
    : if i create these groups and usernames and passwords in a MySQL database would it be best to use an 'if, elseif, else' statement to determine which type of user is trying to access information or is there a better way?
    :
    : also what is the code to load a certain page when an if statement returns true? ex: if ($a == $b){ #?#loadthispage#?#; } else { #?#loadthispage#?#; }
    : can't seem to find it.
    :
  • drksprklsdrksprkls Posts: 6Member
    after reading this i went "ohhhh" haha thanks man


    : I would use binary operators create flags per page and per user. For example... the first bit indicates the first access level, second bit is the second access level, third bit is the third access level. Thus:
    :
    : Group one users will have an access level of 1 (0000 0001)
    : Group two users will have an access level of 3 (0000 0011)
    : Group three users will have an access of 7 (0000 0111)
    :
    : Then for each page, define an access level (1 - first bit, 2 - second bit, or 4 - third bit). Then you only need one if.
    :
    : [code]
    : define (ACCESS_LOW, 1);
    : define (ACCESS_MED, 2);
    : define (ACCESS_HIGH, 4);
    :
    : /* let's pretend we're dynamically giving the user a
    : group three access level, for testing purposes */
    : $MyAccess = ACCESS_LOW & ACCESS_MED & ACCESS_HIGH;
    :
    : /* Later in the code, we want to see if he
    : has access to a high level page */
    : if ($MyAccess & ACCESS_HIGH)
    : {
    : // user has access to area
    : }
    : [/code]
    :
    : To load a page at a given point of code you can either use include/require, which will essentially stick all the code of the file into the current point of execution, or you can use a redirect (see: server-side redirects using Location: header and client-side redirects using Javascript, and meta tags)
    :
    : T
    :
    : : i want to make a login to protect certain areas of a site.
    : : i want 3 different "user groups"
    : :
    : : group one will have access to pages 1, 2, and 3
    : : group two will have access to pages 1, 2, 3, and 4
    : : and group three will have access to pages 1, 2, 3, 4, and 5
    : :
    : : if i create these groups and usernames and passwords in a MySQL database would it be best to use an 'if, elseif, else' statement to determine which type of user is trying to access information or is there a better way?
    : :
    : : also what is the code to load a certain page when an if statement returns true? ex: if ($a == $b){ #?#loadthispage#?#; } else { #?#loadthispage#?#; }
    : : can't seem to find it.
    : :
    :

Sign In or Register to comment.