CENTRAL DO CLIENTE   
(usehost) Base de Conhecimentos

Home | Sumário | Favoritos | Contato | Efetuar Login Home | Sumário | Favoritos | Contato | Efetuar Login
Pesquisar na base de dados Pesquisar por categoria
Autenticação HTTP PHP
Detalhes do artigo

Última atualização
11th o June, 2010

Opções de usuário (0 votos)
Nenhum usuário votou.

Como você avaliaria este artigo?
Útil
Inútil
Occasionally you may wish to make certain pages of your site only viewable to a select few. you can do this by using PHPs built in HTTP Authentication. The code needs to go right at the top of your php page so don’t get ‘Headers Already Sent’ errors. You can see that we’ve specified the username and password in the variables at the top of the script you can change these to reflect your own username and password.

You could easily make this authentication more dynamic by checking a database for the username and password. We can get whatever the user typed into the dropdown box by specifying the following superglobals.

//Username:
<?php echo $_SERVER['PHP_AUTH_USER'];?>
//Password:
<?php echo $_SERVER['PHP_AUTH_PW'];?>

The Code


<?php 

$config['admin_username'] = "demo";
$config['admin_password'] = "demo";

if (!($_SERVER['PHP_AUTH_USER'] == $config['admin_username'] && $_SERVER['PHP_AUTH_PW'] == $config['admin_password'])) {
header("WWW-Authenticate: Basic realm=\"Papermashup.com Demo Admin\"");
header("HTTP/1.0 401 Unauthorized");
echo 'This is what happens if you press cancel';
?>
<?php
exit;
}
// if the username and password match show the rest of the content

?>

Be careful when coding the HTTP header lines. In order to guarantee 
maximum compatibility with all browsers, the keyword “Basic” should be
written with an uppercase “B”, the realm string must be enclosed in
double (not single) quotes, and exactly one space should precede the 401 code in the HTTP/1.0 401 header line.

demo


Comentários
Não hpa comentários de visitantes. Comentar
Postou comentário para o artigo "Autenticação HTTP PHP"
Para postar um comentário para este artigo, preencha o formulário a seguir. campos marcados com asterisco são obrigatórios.
   Seu nome:
   Endereço de e-mail:
* Comentário:
* Digite o código a seguir::
 
Artigos relacionados
Não foi encontrado artigos relacionados.
Anexos
Nenhum anexo.

Continuar

Pagamento de Faturas
2ª Via do Boleto Bancário
Digite o N° da Cobrança:

 

Se seu pagamento não for por
boleto bancário, acesse a nossa
Central do Cliente. E proceda o pagamento.

UMA EMPRESA DO GRUPO INTECORP TECNOLOGIA®
(C) Copyright 2004-2010 (usehost) Serviços de Internet do Brasil.
Compartilhe: