user authentication problem
| From: | chip dot wiegand at simrad dot com | Date: | Tue, 13 Aug 2002 19:27:09 +0000 |
| Subject: | user authentication problem | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-21123@lists.php.net to get a copy of this message | ||
I have this script which is giving me a couple of problems -
1 - I cannot use include "../connect.inc", I get headers already sent error
2 - I can use this script once, but if I try to reload the page to continue
testing I get error "Unable to execute query". Clearing the browsers cache
does not help.
Any ideas what's going on here?
<?
$auth = false; // Assume user is not authenticated
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
//Connect to MySQL
mysql_connect( 'localhost', 'autopilots', 'Xfm3dwj' )
or die ( 'Unable to connect to server.' );
//Select database on MySQL server
mysql_select_db( 'www2_simradusa_com' )
or die ( 'Unable to select database.' );
// Formulate the query
$sql = "SELECT * FROM user WHERE
userid = '$PHP_AUTH_USER' AND
userpassword = '$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query( $sql );
if ( $result != false )
{ echo mysql_error(); }
// Get number of rows in $result.
$num = mysql_numrows( $result );
if ( $num != 0 ) {
// A matching row was found - the user is authenticated.
$auth = true;
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
header( 'Location:
http://www.simradusa.com/auth_dealers/dealers_page.php'
);
}
?>
--
Chip Wiegand
Computer Services
Simrad, Inc
www.simradusa.com
chip.wiegand@simrad.com
"There is no reason anyone would want a computer in their home."
--Ken Olson, president, chairman and founder of Digital Equipment
Corporation, 1977
(They why do I have 9? Somebody help me!)