Hello all,
I have made an internal website for employees to enter information concerning days there are not at work and there current placements.
My problems concerns a log in I have tried to make work :
Code : php4
Database : MySql
Name of database : orange
Name of table concerned (for the login name and password) : utilisateurs
In utilisateurs there is nom_utilisateur (log in name) and mot_de_passe (password) both are varchar(20).
My index page as only one link called "Log in" wich pop ups the log in window but I cannot log in, nom_utilisateur and mot_de_passe are not verified and I don't know why. The only way it work its if I change manually the variable $auth to TRUE, but that doesn't make the code work. Please can you have a look at my code :
So when you click on the link log in in my index page it links to the following code :
<?php # Listing 7.1 - auth.php
$auth = FALSE; // initiating variable
// authentification
if ((isset($SERVER['PHP_AUTH_USER']) AND
isset($SERVER['PHP_AUTH_PW'])))
{ // defining information to access database
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
define ('DB_NAME', 'orange');
//Establish connection and choosing database
$bd = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD)
OR die ('Connexion à MySQL impossible : '.mysql_error());
mysql_select_db (DB_NAME)
OR die ('Selection de la base de données impossible : '.mysql_error());
//Interrogating database
$rq = "SELECT nom_utilisateur FROM utilisateurs WHERE nom_utilisateur ={$_SERVEUR['PHP_AUTH_USER']}
AND mot_de_passe = PASSWORD('{$SERVER['PHP_AUTH_PW']}')";
$result = mysql_query ($rq);
$ligne = @mysql_fetch_array ($result);
if (!$ligne)
{ // if a save has been sent
$auth = TRUE;
}
}
//If nothing is found creat pop up window
if ($auth)
{ header('WWW-Authenticate: Basic realm= "CheckMyApprentice"');
header ('HTTP/1.0 401 Unauthorized'); // Coup d'arrêt
}
?>
<?php # Listing 7.2 - index2.php
// asks authentification
require_once ('auth.php');
?>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN"
"http://www.w3.org/TR/2000/REC-xhtml1 - 20000126/DTD/
xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-1" />
<title>Page d'acceuil</title>
</head>
<body>
<?php
// Prints on the screen the following if not found
if (!$auth)
{
echo "<p>Nom et/ou mot de passe incorrects.".
"Cliquez <a href='index2.php'>ICI</a> pour réessayer. </p>";
}
else
{ echo '<p>Votre authentification a réussi.</p>';
}
?>
</body>
</html>