
É minha primeira vez aqui no forum. Gostei muito desse artigo, simples e direto. Só que testei aqui no meu pc e não deu certo. Você poderia me dar uma ajuda???

Tenho alguma experiencia em GNU/Linux, mas de php OO tô começando agora.

Esse script sempre retorna a mensagem "LOGIN INválido".
Tô usando PHP5 e MySQL 5.0.
Aqui vai o códifgo do meu login.php:
<!--
jovino@jovino-desktop:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10 to server version: 5.0.24a-Debian_9ubuntu2-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
myaql>create database LAX;
mysql> use LAX;
Database changed
mysql> CREATE TABLE `usuario` (
`id` int(11) NOT NULL default '0',
`login` varchar(42) NOT NULL default '',
`senha` varchar(42) NOT NULL default ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on LAX.* to jovino@localhost identified by '123456';
Query OK, 0 rows affected (0.02 sec)
mysql> insert into usuario values(1,'jovino','123456');
Query OK, 1 row affected (0.02 sec)
mysql> show fields from usuario
-> ;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | | 0 | |
| login | varchar(42) | NO | | | |
| senha | varchar(42) | NO | | | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> select * from usuario;
+----+--------+--------+
| id | login | senha |
+----+--------+--------+
| 1 | jovino | 123456 |
+----+--------+--------+
1 row in set (0.00 sec)
mysql> exit
Bye
jovino@jovino-desktop:~$
$logou = $logar->autentica("usuario",$_POST['login'],$_POST['senha']);
-->
<?
#CLASSE USUÁRIO
class User{
#MÉTODO CONSTRUTOR.
#Dados para conexão com o BD.
function __construct($host, $user, $pass, $banco)
{
#DEFINE OS VALORES PARA CONEXÃO COM O BANCO DE DADOS
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->banco = $banco;
#Tentativa de conexão com o banco
self::connect();
}
function connect()
{
#CONECTA-SE AO BANCO DE DADOS COM OS VALORES SETADOS PELO MÉTODO CONSTRUTOR
$conexao = mysql_connect($this->host,$this->user,$this->pass) or die("ERRO1: ".mysql_error());
$banco = mysql_select_db($this->banco,$conexao) or die("ERRO2: ".mysql_error());
return $conexao;
}
function autentica($tbl, $login, $senha)
{
#CHAMA O MÉTODO DE CONEXÃO COM O BANCO DE DADOS.
self::connect();
#VERIFICA SE EXISTE ALGUM LOGIN CADASTRADO NO BANCO COM O INFOMRADO.
$query = mysql_query("select login from $tbl WHERE login='".sha1($login)."' ") or die("ERRO3: ".mysql_error());
#SE ENCONTROU ALGUM USUÁRIO, VERIFICA A SENHA.
if(mysql_num_rows($query)>0):
#RESGATA OS VALORES DOS REGISTROS DO USUÁRIO REFERENTE AO LOGIN INFORMADO.
$dados = mysql_fetch_array($query);
#VERIFICA SE A SENHA INFORMADA É VÁLIDA.
$sql = mysql_query("select senha from $tbl WHERE login='".sha1($login)."' AND senha='".sha1($senha)."' ") or die("ERRO4: ".mysql_error());
if(mysql_num_rows($sql)>0):
$this->msg = "LOGADO COM SUCESSO";
else:
$this->msg = "SENHA INVÁLIDA";
endif;
else:
$this->msg = "LOGIN INVÁLIDO";
endif;
return $this->msg;
}
}
#PASSA OS PARÂMETROS DE CONEXÃO COM O BANCO DE DADOS.
$logar = new User("localhost","jovino","123456","LAX");
#VERIFICA A ENTRADA DOS CAMPOS.
if(!empty($_POST['login']) && !empty($_POST['senha']) ):
#FAZ A AUTENTICAÇÃO.
$logou = $logar->autentica("usuario",$_POST['login'],$_POST['senha']);
endif;
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<table border="0" width="550" align="center">
<tr>
<td colspan="2"><div align="center"><strong>Autenticação de Usuário</strong></div></td>
</tr>
<?
if(isset($logou)):
?>
<tr>
<td colspan="2"><div align="center"><strong><font color="#FF0000"><?=$logou?></font></strong></div></td>
</tr>
<?
endif;
?>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Login</td>
<td><input type="text" name="login"></td>
</tr>
<tr>
<td>Senha</td>
<td><input type="password" name="senha"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Logar"></td>
</tr>
</table>
</form>