Restricted access php variables

I’m sure i’m missing something really stupid, but my website logs user session based on usernames “$user_name” and i have a band page where anyone who’s listed as a band manager can access the page (band managers are $bandm1 $bandm2 $bandm3 $bandm4) how would i write a script that if $username = bandm1, bandm2, bandm3, or bandm4 then the user has access to the page, but if none of those = $user_name then the user DOES NOT have access to the page

They are listed as a band manager where exactly? In a database?

the bands table in my database has a 4 columns listed as bandm1 ect

the data model is poorly designed, but that is how you would do the restriction.

how im already doing it? thats not working though

If your data model was normalized, you could do something like this,

SELECT COUNT(*) FROM `band_roles` WHERE band_id = ? AND role_id = (SELECT id FROM roles WHERE name = 'Manager') AND user_id = ?

If you get 1 back they are the manager for that band. If 0, they shouldn’t have access.

Sponsor our Newsletter | Privacy Policy | Terms of Service