I think what you want is a way to not index the domain home page, you can put an "index.php" to authenticate and create in the same an algorithm to list the folder on the web.
Follow a script I prepared for you
<?php
$realm = 'Área restrita';
//usuário => senha
$users = array('admin' => 'senha', 'visitante' => 'senha');
function authNow() {
global $realm;
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Digest realm="'.$realm.'",qop="auth",nonce="'.uniqid().'",opaque="'.md5($realm).'"');
die('Não foi possível validar seus dados');
}
if (empty($_SERVER['PHP_AUTH_DIGEST'])) {
authNow();
}
// analisar a variável PHP_AUTH_DIGEST
if (!($data = http_digest_parse($_SERVER['PHP_AUTH_DIGEST'])) ||
!isset($users[$data['username']])) {
authNow();
}
// gerar a resposta válida
$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
if ($data['response'] != $valid_response) {
authNow();
}
// listando diretórios
$dirs = array_filter(glob('*'), 'is_dir');
echo '<h1>Início em /</h1><hr/>';
echo '<ul>';
foreach($dirs as $dir) {
echo '<li><a href="'.$dir.'">' . $dir . '</a></li>';
}
echo '</ul><hr/>Página gerada em ' . date('d/m/Y H:i:s');
// função para decompor o http auth header
function http_digest_parse($txt)
{
// proteção contra dados incompletos
$needed_parts = array('nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1);
$data = array();
$keys = implode('|', array_keys($needed_parts));
preg_match_all('@(' . $keys . ')=(?:([\'"])([^\2]+?)\2|([^\s,]+))@', $txt, $matches, PREG_SET_ORDER);
foreach ($matches as $m) {
$data[$m[1]] = $m[3] ? $m[3] : $m[4];
unset($needed_parts[$m[1]]);
}
return $needed_parts ? false : $data;
}
Boys thanks for the help, but yes it is possible yes, with the use of Linux password I can even make put in one of the companies my boss did so and becomes practical for simple things.
– Bulfaitelo