Ciao a tutti.
Vi premetto che sono una newbie (3 giorni di PHP).
Allora...
Il mio file login.php deve ottenere username e password in un form e autenticare le variabili fornite con una funzione. Le variabili devono essere identiche a $HOSTUSER e $HOSTPWD che con in un file incluso (conn.inc.php) da login.php. Sfortunatamente, gli echo didebug nella funzione authenticated del file login.php mi stampa come stringhe vuole le variabili in cluse da conn.inc.php.
Ecco il file conn.inc.php:
<?php
$HOSTNAME="mydb.mydomain";
$HOSTDB="MYDB";
$HOSTUSER="pippo";
$HOSTPWD="CANTERINO";
?>
ecco il file login.php:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<?php include("menu.php");
include('conn.inc.php');
?>
<title>Login</title>
</head>
<body>
<?php echo '<form name="formname" action="login.php" method="post">';
?>
<form>
<p class="form">username :<input type="text" name="username"></p>
<p class="form">password :<input type="password" name="password"></p>
<input type="submit" value="invia">
</form>
<?php
function authenticated($username, $password){
// If either the username or the password are
// not set, the user is not authenticated
if (!isset($username) || !isset($password))
return false;
if ($username == '' && $password == ''){
echo "Empty Fields!
";
return false;
}
//debug
echo "
HOSTUSER: $HOSTUSER, </p>
";
echo "
HOSTPWD: $HOSTPWD, </p>
";
echo "
username: $username, </p>
";
echo "
password: $password, </p>
";
if ((strcmp($HOSTUSER, $username) == 0)
&&
strcmp($HOSTPWD, $password) == 0) {
echo "true!
";
return true;
}
else
return false;
}
if (!authenticated($_POST['username'],$_POST['password']))
{
// No credentials found - send an unauthorized
// challenge response
header("WWW-Authenticate: Basic realm=\"Flat Foot\"");
header("HTTP/1.0 401 Unauthorized");
// Set up the body of the response that is
// displayed if the user cancels the challenge
?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<title>Web Database Applications</title>
</head>
<body>
<h2>You need a username and password to
access this service</h2>
If you have lost or forgotten your
password, tough!
</body>
</html>
<?php
exit;
}
// The response to authorized users
?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<title>Web Database Applications</title>
</head>
<body>
<h2>Welcome!</h2>
</body>
</html>
----------------
Quando mi connetto a login.php tramite Firefox, io metto la coppia username/pwd giusta (pippo+CANTERINO) ma ho l seguente output su login.php:
HOSTUSER: ,
HOSTPWD: ,
username: pippo,
password: CANTERINO,
You need a username and password to access this service
If you have lost or forgotten your password, tough!
--------------------
Dov'è l'errore? $HOSTUSER E $HOSTPWD sono globali e incluse nel file che contiene la funzione che le accede...bah... ho provato anche a metterle come globali direttamente in login.pho senza includere conn.inc.php
...
help me...![]()