Domanda

Sto cercando di proteggere una cartella utilizzando ".htaccess" e ".htpasswd".

ero solito http://www.tools.dynamicdrive.com/password/ per generare i file.

Li ho copiati nelle cartelle corrispondenti.

Quando ho tentato di accedere alla cartella protetta, Ho ricevuto una richiesta di accesso.

Inserisci dettagli di accesso errati, vieni inviato alla pagina di errore.

Tutto bene.

Ora, senza alcuna modifica, rivisita la pagina per provare ad accedere nuovamente per accedere alla cartella protetta e viene generato solo un errore, non c'è una casella di accesso.

Se elimino il file .htaccess, posso accedere nuovamente alla cartella senza errori.

Dopo aver sostituito .htacces, ricevo di nuovo l'errore, ancora nessuna casella di accesso.

Ho provato a rigenerare un nuovo set di file, una combinazione utente/passaggio e lievi modifiche a .htaccess solo per provare a ottenere una qualche forma di risposta.

Ho controllato eventuali bytemark, entrambi i file sono UTF-8 puliti.

Cosa sta succedendo?Perché non ricevo più un messaggio?

Nota a margine: dove dovrebbe essere il registro?Tutto quello che sono riuscito a trovare sono stati alcuni registri di accesso che non contenevano nulla di utile.


Posizione del sito sul server

/home/labvccom/

/home/labvccom/public_html/admin/.htaccess

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /htpasswords/.htpasswd
AuthGroupFile /dev/null
require valid-user

/home/labvccom/htpasswords/.htpasswd [utente:amministratore | passaggio:parola d'ordine]

admin:02yd6IWnPes66

Questa è la pagina che ottengo quando viene generato l'errore SENZA prompt di accesso

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@labvc.com.au and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 mod_fcgid/2.3.5 Phusion_Passenger/2.2.15 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at labvc.com.au Port 80
È stato utile?

Soluzione

Il tuo browser ricorda il primo tentativo di accesso e invia le credenziali in Autorizzazione Intestazione: ecco perché non si ottiene un nuovo prompt di accesso.

Prova a cancellare la cache di autorizzazione.

Il problema sottostante è molto probabile come suggerisce @OpenScript.ch.

Altri suggerimenti

Penso che il tuo percorso verso il file .htpasswd sia sbagliato. Se non è assoluto, viene trattato come relativo al serverroot. Prova a utilizzare un percorso assoluto per il tuo file .htpasswd.

Devi creare login/pass .htaccess all'interno della cartella che vuoi proteggere...altrimenti il ​​trucco non funzionerà come desiderato!Ho creato alcuni giorni fa un semplice strumento php che crea login/pass per te.Fa parte di un altro mio progetto...quindi l'ho estratto dal mio archivio per te.Fare attenzione che sotto windows la password venga inviata in chiaro...non è un bug del mio script ma una richiesta dei server Windows.Quindi usalo solo in hosting remoto con Unix, Linux con Apache.Metti apache-ht.php nella cartella che vuoi proteggere e poi eseguilo.Ti verrà richiesto di creare utente/pass!Al termine, elimina apache-ht.php dalla cartella.Fallisci perché stai cercando di impostare il percorso relativo.Questo tipo di .htaccess necessita del percorso completo!Spero che aiuti:

apache-ht.php

<?php
  ############################################
  # Created By Alessandro Marinuzzi [Alecos] #
  # apache-ht.php - Version 1.5 - 07/04/2015 #
  # WebSite: ---> http://www.alecos.it/ <--- #
  ############################################
  if ((isset($_POST['username']) && (!empty($_POST['username']))) && ((isset($_POST['password'])) && (!empty($_POST['password'])))) {
    $username = $_POST['username'];
    $password = $_POST['password'];
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Apache - Username :: Password Generator</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Oswald);
@import url(http://fonts.googleapis.com/css?family=Roboto+Condensed);
html {
  display: table;
}
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
  background-color: lightgray;
  display: table-cell;
  vertical-align: middle;
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
}
.mainbox {
  border-radius: 7px;
  border: 1px solid gray;
  background-color: darkgray;
  width: 420px;
  height: auto;
  margin-top: 50px;
  margin-bottom: 50px;
  vertical-align: middle;
  text-align: center;
  margin: 0 auto;
  padding: 20px;
}
.title {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 24px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  vertical-align: middle;
  text-align: center;
}
.save {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 20px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  border-radius: 3px;
  border: 1px solid black;
  background-color: darkviolet;
  cursor: pointer;
  box-shadow: inset -5px 5px 5px rgba(255, 255, 255, 0.15), inset 5px -5px 5px rgba(0, 0, 0, 0.15);
  vertical-align: middle;
  text-align: center;
  padding: 10px;
}
.data {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 17px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  vertical-align: middle;
  text-align: center;
}
.doit {
  vertical-align: middle;
  text-align: center;
}
.user {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  background-color: #006699;
  border: #C0C0C0 2px solid;
  vertical-align: middle;
  text-align: center;
  border-radius: 3px;
  color: white;
  width: 80px;
  margin: 5px;
}
.pass {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  background-color: #006699;
  border: #C0C0C0 2px solid;
  vertical-align: middle;
  text-align: center;
  border-radius: 3px;
  color: white;
  width: 80px;
  margin: 5px;
}
</style>
</head>
<body>
<?php
    if ((substr($_SERVER['DOCUMENT_ROOT'],-1,1) == "/") && (substr($_SERVER['PHP_SELF'],0,1) =="/")) {
      $path = $_SERVER['DOCUMENT_ROOT'] . substr(dirname($_SERVER['PHP_SELF']),1) . "/.htpasswd";
    } else {
      $path = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']) . "/.htpasswd";
    }
    $tmp1 = fopen(".htaccess", "w");
    $tmp2 = "AuthType Basic\n";
    $tmp2 .= "AuthName \"Restricted Area\"\n";
    $tmp2 .= "AuthUserFile \"$path\"\n";
    $tmp2 .= "Require valid-user\n";
    fwrite($tmp1, $tmp2);
    fclose($tmp1);
    unset($tmp1);
    unset($tmp2);
    if (strtoupper(substr(PHP_OS,0,3) == 'WIN')) {
      $tmp1 = fopen(".htpasswd", "w");
      $tmp2 = "$username:$password\n";
      fwrite($tmp1, $tmp2);
      fclose($tmp1);
      unset($tmp1);
      unset($tmp2);
    } else {
      $tmp1 = fopen(".htpasswd", "w");
      $tmp2 = "$username:" . crypt($password,'$6$rounds=5000$usesomesillystringforsalt$') . "\n";
      fwrite($tmp1, $tmp2);
      fclose($tmp1);
      unset($tmp1);
      unset($tmp2);
    }
    exit("<div class=\"mainbox\">\n<span class=\"title\">Apache - Username :: Password Generated!</span>\n</div>\n</body>\n</html>");
  }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Apache - Username :: Password Generator</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Oswald);
@import url(http://fonts.googleapis.com/css?family=Roboto+Condensed);
html {
  display: table;
}
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
body {
  background-color: lightgray;
  display: table-cell;
  vertical-align: middle;
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
}
.mainbox {
  border-radius: 7px;
  border: 1px solid gray;
  background-color: darkgray;
  width: 420px;
  height: auto;
  margin-top: 50px;
  margin-bottom: 50px;
  vertical-align: middle;
  text-align: center;
  margin: 0 auto;
  padding: 20px;
}
.title {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 24px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  vertical-align: middle;
  text-align: center;
}
.save {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 20px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  border-radius: 3px;
  border: 1px solid black;
  background-color: darkviolet;
  cursor: pointer;
  box-shadow: inset -5px 5px 5px rgba(255, 255, 255, 0.15), inset 5px -5px 5px rgba(0, 0, 0, 0.15);
  vertical-align: middle;
  text-align: center;
  padding: 10px;
}
.data {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 17px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  vertical-align: middle;
  text-align: center;
}
.doit {
  vertical-align: middle;
  text-align: center;
}
.user {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  background-color: #006699;
  border: #C0C0C0 2px solid;
  vertical-align: middle;
  text-align: center;
  border-radius: 3px;
  color: white;
  width: 80px;
  margin: 5px;
}
.pass {
  font-family: Oswald, 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  font-style: normal;
  line-height: normal;
  font-weight: normal;
  font-variant: normal;
  background-color: #006699;
  border: #C0C0C0 2px solid;
  vertical-align: middle;
  text-align: center;
  border-radius: 3px;
  color: white;
  width: 80px;
  margin: 5px;
}
</style>
</head>
<body>
<div class="mainbox">
<span class="title">Apache - Username :: Password Generator</span><br>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<span class="data"><label for="username">Username:</label> <input type="text" class="user" id="username" name="username"></span><br>
<span class="data"><label for="password">Password:</label> <input type="text" class="pass" id="password" name="password"></span><br>
<span class="doit"><input type="submit" class="save" value="Create Username &amp; Password"></span><br>
</form>
</div>
</body>
</html>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top