Mysql PHP one password to access multiple databases on same host

Posted on 2011-04-19
Last Modified: 2012-05-11
I have an app where I want to allow a user to access more than one database on the same host.   They will all enter through the same initial database.

I want to add "restrict access" to each page, so they can only access pages based on their "access level" which is stored in a users table

Question by:debbieau1
    LVL 20

    Accepted Solution

    I do this for most of my CMS websites. Firstly, in your users table add a column and name it "level" and make it int(1)

    Now what I do is make anyone signing up a level 1. When they try to log on and they are level 1 they get a warning they need to check their email and click a link to confirm their email address. Once that has been done they are moved to level 2. From there if you want to assign different levels to different users for different access, just retrieve their level at login stage and do a simple if statement.

    if($level == 3){
    include("level3_page.php"); // of whatever level 3 page you have
    }elseif($level == 4){
    } // I think you can see where I'm going with this.

    All you need to do is use php sessions() in each page to keep track of that users level then at the top of each page you check to see if that user has the right level to access that page. If not, redirect them back to the page they should be viewing.

    you can either do it like that or you can write different code depending on their level but storing their level in the users table is the easiest way I find.
    LVL 1

    Author Comment

    Hi I am currently using levels.  Wasn't sure if the user authentication in one database, carried through if you were using another.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now