How WHAT should be done. You keep asking about your ATTEMPTED SOLUTION to the REAL problem. This is a classic XY Problem. https://xyproblem.info/
THIS is the REAL problem I was asking for.
“im trying to prevent access to the files if they dont have access to them”
In this case, if you want only authorized users to access the admin sub directory, you first need to authenticate the user and get their permissions if there are multiple access levels, then set a session that will pass a check in the admin to allow them in there.
Your going to have to show more than a single hard coded path piece of code if you want any real answers. We have no idea what you have going on. How about posting the actual class.
What is the site architecture? Do you have a single point of entry like you “should” or are you serving individual pages with each url.
If you can, it would be helpful if you put your app on GitHub so we can review it as a whole.