Jump to content
Fórum Script Brasil
  • 0

Autenticação De Usuarios Via Http Usando Mysql E Session


Beraldo
 Share

Question

Script postado por: Fabyo

Autenticação de Usuarios via HTTP Usando MySQL e Session

/*Autor Fabyo guimaraes*/

//banco
/*CREATE TABLE `usuarios` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `login` varchar(40) NOT NULL default '',
  `senha` varchar(32) NOT NULL default '',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;

*/
<?php

session_start();

$nome  = "";
$senha = "";

//conexao com o banco
$cn = mysql_connect("localhost");
mysql_select_db("online",$cn);

if (isset($_SERVER["PHP_AUTH_USER"]) || isset($_SERVER["PHP_AUTH_PW"])){ 

$nome = $_SERVER["PHP_AUTH_USER"];
$senha = $_SERVER["PHP_AUTH_PW"];

}

$query = mysql_query("SELECT * FROM usuarios WHERE nome = '$nome' and senha = [color=red]md5[/color]('$senha')");
$contagem = mysql_num_rows($query);

if ($contagem == 0) {

    header('WWW-Authenticate: Basic realm = "Acesso Restrito"');
    header('HTTP/1.0 401 Unauthorized');
    echo '<center><h1>Acesso Restrito</h1></center>';
    exit;
}
else{

//cria a sessao
$_SESSION["usuario"] = $nome;

//redireciona o usuario para pagina principal
header("Location: principal.php");

}
?>

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      151k
    • Total Posts
      649.1k
×
×
  • Create New...