PHP auth with access

Discussion in 'Programming' started by BT Buses, Feb 21, 2008.

  1. #1
    I have a working script to allow people into a particular page on my site, but what im wanting is to restrict what people are able to see from the links after a successfull login.

    Here is the login script
    But what i'm wanting is say user 'Test1' to be able to see all the links once they have successfully logged on, but say user 'Test2' to be only able to see link 2, and say if there was a 3rd user, to be able to see links 1 & 3, but not 2.
    So is this possible? And if so, anyone able to help me with it as i'm totally lost.

    Thanks in advance...
     
    BT Buses, Feb 21, 2008 IP
  2. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Store what user they are once they login...? $_SESSION['user'] = $_POST['username'];

    Then, do something like this to display links..

    switch($_SESSION['user']) {
      case "Test1";
        echo 'link 1
              link 2
              link 3';
        break;
      case "Test2";
        echo 'link 2';
        break;
      case "Test3";
        echo 'link 1
              link 3';
        break;
    }
    PHP:
    Of course, you could also just do a bunch of IF statements (switches can be better for things like this).
    $user = $_SESSION['user']; #too lazy to keep typing out $_SESSION['user']
    if($user=='Test1') {
      echo 'link 1
            link 2
            link 3';
    } elseif($user=='Test2') {
      echo 'link 2';
    } elseif($user=='Test3') {
      echo 'link 1
            link 3';
    }
    PHP:
     
    zerxer, Feb 21, 2008 IP
  3. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Are you really going to be defining what each and every one of your users are going to be seeing on an individual basis or are you really taking about having "roles"?

    If it is groups of people then simply set a session item for which role that particular user belongs to and test for that role rather than that user when deciding if an item should be shown or not (aka roles based access control)
     
    AstarothSolutions, Feb 21, 2008 IP
  4. daringtakers

    daringtakers Well-Known Member

    Messages:
    808
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    110
    #4
    Seems that you are you need some authorization done for every user, is it?
     
    daringtakers, Feb 22, 2008 IP