HSN
Wed 13th Aug '03, 8:46am
Hello,
I'm writing a script for authentication purposes:
<?php //Authentication
$authentication = FALSE;
if ( isset ($_SERVER['PHP_AUTH_USER']) AND isset ($_SERVER['PHP_AUTH_PW']) )
{
require_once ("connect.php");
$query = "SELECT user_id FROM users WHERE username = '{$_SERVER['PHP_AUTH_USER']}' AND password = PASSWORD ('{$_SERVER['PHP_AUTH_PW']}')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result);
if ($row)
{
$authentication = TRUE;
}
else
{
echo "Not OK!";
}
}
if (!$authentication)
{
header ( ' WWW-Authenticate: Basic realm = "My Web Site" ' );
header('HTTP/1.0 401 Unauthorized');
}
?>
But it does not give the permission! In fact it doesn't go through the first if statement:
if ( isset ($_SERVER['PHP_AUTH_USER']) AND isset ($_SERVER['PHP_AUTH_PW']) )
{
require_once ("connect.php");
$query = "SELECT user_id FROM users WHERE username = '{$_SERVER['PHP_AUTH_USER']}' AND password = PASSWORD ('{$_SERVER['PHP_AUTH_PW']}')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result);
.
.
.
Please help me with it.
I'm writing a script for authentication purposes:
<?php //Authentication
$authentication = FALSE;
if ( isset ($_SERVER['PHP_AUTH_USER']) AND isset ($_SERVER['PHP_AUTH_PW']) )
{
require_once ("connect.php");
$query = "SELECT user_id FROM users WHERE username = '{$_SERVER['PHP_AUTH_USER']}' AND password = PASSWORD ('{$_SERVER['PHP_AUTH_PW']}')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result);
if ($row)
{
$authentication = TRUE;
}
else
{
echo "Not OK!";
}
}
if (!$authentication)
{
header ( ' WWW-Authenticate: Basic realm = "My Web Site" ' );
header('HTTP/1.0 401 Unauthorized');
}
?>
But it does not give the permission! In fact it doesn't go through the first if statement:
if ( isset ($_SERVER['PHP_AUTH_USER']) AND isset ($_SERVER['PHP_AUTH_PW']) )
{
require_once ("connect.php");
$query = "SELECT user_id FROM users WHERE username = '{$_SERVER['PHP_AUTH_USER']}' AND password = PASSWORD ('{$_SERVER['PHP_AUTH_PW']}')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result);
.
.
.
Please help me with it.