note 36764 deleted from features.http-auth by vincent
| From: | vincent@php.net | Date: | Tue, 21 Oct 2003 18:24:43 +0000 |
| Subject: | note 36764 deleted from features.http-auth by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59053@lists.php.net to get a copy of this message | ||
Note Submitter: daniloplara@yahoo.com.br
----
Assim deu certo.
--------------------------------------------------------
<?
$auth = false;
if (isset( $PHP_AUTH_USER ) && isset($PHP_AUTH_PW)) {
#------> conecta ao banco de dados mysql <----#
mysql_connect( 'hostname', 'username', 'password' )
or die ( 'Não foi possivel conectar ao servidor.' );
#-------------> seleciona a tabela <------------#
mysql_select_db( 'sua tabela' )
or die ( 'Não há nehuma tabela selecionada.' );
$sql = "SELECT * FROM users WHERE
username = '$PHP_AUTH_USER' AND
password = '$PHP_AUTH_PW'";
$exec= mysql_query( $sql )
or die ( 'Nao foi possivel executar esta sentença.' );
$num = mysql_num_rows( $exec );
if ( $num != 0 ) {
$auth = true;
}
}
if ( ! $auth ) {
header( 'WWW-Authenticate: Basic realm="Private"' );
header( 'HTTP/1.0 401 Unauthorized' );
echo 'Authorization Required.';
exit;
} else {
echo '<div aling='center'>Usuario autorizado!</P>';
}
?>
--------------------------------------------------------