1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Php user authentication to bootstrap page

Discussion in 'PHP' started by Hubert jiang, Feb 24, 2015.

  1. #1
    hi guys

    I designed a log in page using php to authenticate to differentiate the user rights. There are 3 types of user - admin, staff, and ground. This users will enter credentials into login form and will enter into home page. As each users are only allowed to access certain content, I will like to show only relevant contents to the users. So from login page (index.php) they will go into home page (home.php).

    I used bootstrap to design the home page thus showing 2 rows of 3 columns. The aim for bootstrap is to allow the web application to be responsive so users can login using desktop, tablet or even mobile.

    I like to filter the bootstrap columns such as admin can see all 6 columns, staff can see 5 of the columns while ground users can only see 2 of the columns. I am not sure if I can use php to filter the columns out.

    Is this possible?

    Thanks in advance. Sorry if I posted in wrong section.
     
    Solved! View solution.
    Hubert jiang, Feb 24, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Of course you can. Depending on how you fetch the user role, you can check against that before outputting anything, for instance. This is pretty much basic user rights handling.
     
    PoPSiCLe, Feb 24, 2015 IP
  3. Hubert jiang

    Hubert jiang Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Thanks. at least I see a possibility. Do you also know if there any best practice for doing so? or like any tutorial I can read and follow through to achieve that?
     
    Hubert jiang, Feb 24, 2015 IP
  4. mohanprakash

    mohanprakash Greenhorn

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    yaa, it can be done by apply condition on user type(admin,staff,ground) for all three type of user show separate column or apply conditions
     
    mohanprakash, Feb 24, 2015 IP
  5. #5
    Well, since I've no idea about how you grant the user role to the logged in user, there isn't really an easy way to say "do it like this". Normally you'd have a user-class, which would contain all the needed attributes for that user (if you're coding OOP) - if not, and you're using a procedural approach, you can still assign the userrole (pulling it from the database) to a variable or defined constant or something similar. Then you can just do something like this:
    
    if ($userrole == 'admin') {
    // show admin-stuff
    }
    
    PHP:
    Normally you'd have levels - so regular user is say assinged the value 9, a moderator is assigned a value 6 and an admin is assigned a value 1 or 2 - then you can do something like this:
    
    if ($userrole >= 6) {
    //show something here, for both moderators and admins
    }
    
    PHP:
    This would be one way
     
    PoPSiCLe, Feb 25, 2015 IP
  6. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #6
    It's all around menu control - when you generate the menu you check their user type and output the appropriate options - and it may depend on your CMS or framework if you are using one.

    The only other thing you have to consider is if staff send an email with a link to ground and ground clicks the link should they see the content even if they normally wouldn't?
     
    sarahk, Feb 25, 2015 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Granted, that works for the menu, but unless you're also checking the content-pages for the correct credentials, all that does is prevent a user having direct access to sub-pages - and in this particular case, as I understood it, there's not really a menu involved - it's just showing content based on what access the user have (or, currently, just showing content, if I get the OP's question). Granted, the principle is the same.
     
    PoPSiCLe, Feb 26, 2015 IP
  8. Hubert jiang

    Hubert jiang Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #8
    Thanks Guys. I will try it soon. Anyway if I use the If condition for the different user groups, I will duplicate the codes as many times as the user groups I have right? just that within each duplication, there will be difference in the section to be shown, am I right?
     
    Hubert jiang, Feb 27, 2015 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    As I mentioned, you could do a sliding access grant - if you use numerical values for the roles, and then give access for anyone above (or below) that given limit - that way you can do fewer checks. But yes, you can of course just duplicate the code for each content section, and change the values.
     
    PoPSiCLe, Feb 27, 2015 IP
  10. mohanprakash

    mohanprakash Greenhorn

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #10
    yes in this way you can solve your problem,as you thinking to do it, by applying condition on different user
     
    mohanprakash, Feb 28, 2015 IP
  11. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #11
    While I probably wouldn't be stepping in the steaming pile of developer ineptitude known as bootcrap and tracking it all over a website, I have to wonder just what the blue blazes does logic functionality have to do with presentation?

    Rule #1, if you can't make something like login work with just plain HTML as if CSS and JS never even existed, you shouldn't be trying to write a login / user auth.

    You might want to do yourself a favor, and find a stick to scrape that off with.
     
    deathshadow, Mar 4, 2015 IP
  12. Hubert jiang

    Hubert jiang Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #12
    I think its more of a ACL now, not really log in or user authentication. I do not mind if someone can share with me what is the best practice for user authentication using PHP.
     
    Hubert jiang, Mar 4, 2015 IP
  13. Mark_KW

    Mark_KW Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #13
    Depends on how fast you want that done. User authentication with PHP can be handled quite fast and efficiently.
     
    Mark_KW, Mar 5, 2015 IP