Jump to content

Restricted folder by $_SESSION


etrader

Recommended Posts

I created a session by a login page, and limited the pages by adding this condition to every page

 

if(!isset($_SESSION['level'])){
echo"You are not authorized to visit this page";		
}

 

This works perfectly for every single page, but how I can use it for an entire folder like admin folder ?

Link to comment
Share on other sites

I just gave you a tip, I didn't do the work for you, so you don't just "put the code somewhere".

 

echo that variable to see what you get while inside one of the admin folders. Then you can figure out how to protect the folders by splitting the result and adding another $_SESSION check.

 

Link to comment
Share on other sites

Or you can create a file which checks if the user has the correct permissions of the various files and just include it at the start of each file.

 

Dirty I know, but it works!!!

 

<edit>Sorry, posted that at the same time.  Great minds thing alike!!</edit>

Link to comment
Share on other sites

It seems there is no way to do so. I am currently doing what ZulfadlyAshBurn said. I was looking for a way NOT to edit every single php file in my admin folder. I was looking to make a rule for the entire folder, not every single page.

 

WebStyles, I did not ask you to make it work for me. I just asked you to clarify your tip, as apparently you did not get my issue.

 

Anyway, thank folks! :)

Link to comment
Share on other sites

I was looking to make a rule for the entire folder, not every single page.

 

Easily done with .htaccess  and a bootstrap file. The .htaccess takes any request to the admin folder and redirects to say bootstrap.php. The bootstrap will then parse the request, include the proper file and you can have all the code inside that file that needs to be included on all of those files.

 

RewriteEngine On

RewriteRule ^admin/(.*).php$ bootstrap.php?page=$1 [L]

 

Is a rough example and may need tweaking, but there you go.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.