Connecting/combining multiple user tables in a MySQL database for different PHP applications on a server subdomains/subfolders

StackOverflow https://stackoverflow.com/questions/22816108

  •  26-06-2023
  •  | 
  •  

Question

I have multiple applications on a server's subdomains/subfolders (i.e. domain.com, example1.domain.com, domain.com/example1 and domain.com/example2). There are multiple users tables for these applications in a same MySQL database. My goal is to connect the user tables to not login/logout users from one application to another. Is this a good way to create a new table with all fields from existing user tables and subsequently changing the queries in PHP files? Would you please give me your comment/solution for this problem?

Was it helpful?

Solution

You would need to create a single table for your users info like name,mail,password, etc.

Then create a new table to assign an id to each app you want to manage.

Finally you'll need a permissions table with an id_user column and an id_app column to bind the app to your user.

In each app you'll need to specify its "id" based on the apps table you created before. When a user logs in simply store in an SESSION array all the id_app values from the permissions table where the user's id appears and use in_array function to verify if the user is allowed to access the app.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top