m47h
m47h

Reputation: 1703

Check htaccess permission of subfolder with php

consider the following scenario: A user has successfully logged in via htaccess and should get a list of links to subfolders of the current directory which are accessible with the same credentials he used. Is there a possibility to detect this with php? Something like:

function getAllAccessableSubfolders($subfolders)
{
  $accessableSubfolders = array();
  foreach($subfolder as $sf)
  {
    if($sf is accessable using the same credentials)
    {
      $accessableSubfolders[] = $sf;
    }
  } 
  return $accessableSubfolders;
}

Of course, there is the way of checking if the specific .htaccess files point to the same group- and user file and if the current user belongs to the 'valid user group' in every subfolder. But as there are many possibilities, i would prefer a simpler solution.

Upvotes: 0

Views: 50

Answers (1)

Mike Brant
Mike Brant

Reputation: 71384

You can get user information from $_SERVER['PHP_AUTH_USER']. That being said, you have not shared enough about your user-permissions for me to provide any additional detail (i.e. how do you determine what resources a user has access to?) Try looking at PHP documentation here:

http://php.net/manual/en/features.http-auth.php

I would generally state that basic authentication is probably not the best way to go about implementing a granular user permissions system for your application.

Upvotes: 1

Related Questions