Page 1 sur 1
Fonction PHP_AUTH_USER
Posté : 25 août 2006, 19:13
par Kochi
Voici mon code:
Code : Tout sélectionner
<?php
if (!($_SERVER['PHP_AUTH_USER']=="essai" &&
$_SERVER['PHP_AUTH_PW']=="essai"))
{
header("status: 401 Unauthorized");
header("HTTP/1.0 401 Unauthorized");
header("WWW-authenticate: Basic realm=\"acces securise au back-office\"");
print("Vérification: ERREUR");
exit(0);
}
print("Vérification: OK");
?>
Dans le navigateur cela m'affiche:
Notice: Undefined index: PHP_AUTH_USER in c:\documents and settings\sebastien\mes documents\kochi\test\authentification.php on line 3
À quoi cela est-il dû?
Re: Fonction PHP_AUTH_USER
Posté : 25 août 2006, 19:16
par Invité
Désolé, j'oubliais les bonnes manières;
Bonjours à tous, j'ai un problême, pouvez-vous m'aider
Voici mon code:
Code : Tout sélectionner
<?php
if (!($_SERVER['PHP_AUTH_USER']=="essai" &&
$_SERVER['PHP_AUTH_PW']=="essai"))
{
header("status: 401 Unauthorized");
header("HTTP/1.0 401 Unauthorized");
header("WWW-authenticate: Basic realm="acces securise au back-office"");
print("Vérification: ERREUR");
exit(0);
}
print("Vérification: OK");
?>
Dans le navigateur cela m'affiche:
Notice: Undefined index: PHP_AUTH_USER in c:\documents and settings\sebastien\mes documents\kochi\test\authentification.php on line 3
À quoi cela est-il dû?
Posté : 25 août 2006, 21:09
par Cyrano
As-tu défini tes identifiant quelque part ?
Posté : 26 août 2006, 10:24
par rami
Issu de la
doc :
<?php
function authenticate() {
header('WWW-Authenticate: Basic realm="Test Authentication System"');
header('HTTP/1.0 401 Unauthorized');
echo "Vous devez entrer un identifiant et un mot de passe valide pour accéder
à cette ressource.\n";
exit;
}
if ( !isset($_SERVER['PHP_AUTH_USER']) ||
($_POST['SeenBefore'] == 1 && $_POST['OldAuth'] == $_SERVER['PHP_AUTH_USER'])) {
authenticate();
} else {
echo "<p>Bienvenue : {$_SERVER['PHP_AUTH_USER']}<br />";
echo "Ancien : {$_REQUEST['OldAuth']}";
echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"SeenBefore\" value=\"1\">\n";
echo "<input type=\"hidden\" name=\"OldAuth\" value=\"{$_SERVER['PHP_AUTH_USER']}\">\n";
echo "<input type=\"submit\" value=\"Identification\">\n";
echo "</form></p>\n";
}
?>