0
I made a login system in PHP where, after authentication, I go back to the page index.php
.
So far so good, the problem is that when I redirect the user to the index.php
again, it asks me for login data.
Someone knows what I’m doing wrong?
Follow the page index.php
:
<?php
if(!isset($_SESSION)){
session_start();
}
if(!isset($_SESSION["$Email"])){
echo 'todos os forms de login';
}
else{
echo 'todo o site';
}
And here is the authentication function:
public function autenticacao($Email, $Senha){
$oConexao = new conexaoclass();
$oConexao -> abrirConexao();
$sql = "SELECT * FROM Professores
WHERE Email = '$Email' AND Senha = '$Senha'";
$this -> resultado = mysql_query ($sql, $oConexao -> getConn());
$rows = mysql_num_rows($this -> resultado);
if ($rows > 0) {
session_start();
$_SESSION["$Email"] = $Email;
$_SESSION["$Senha"] = $Senha;
echo "Login realizado com sucesso! <br> Aguarde, você será redirecionado...";
echo "<script>login()</script>";
}
else{
echo "Login inválido!!! Dados incorretos! <br> Aguarde, você será redirecionado...";
echo "<script>loginFail()</script>";
}
}
Instead of $_SESSION['$email'] use $_SESSION['email'] = $email.
– touchmx
Maybe it’s not the focus of the question. But always try to avoid keeping a pure password in the bank. Try to store the encrypted password and at the time of authentication only compare the encrypted passwords. Security issue. If you are interested here you have a good discussion on the subject: http://answall.com/questions/2402/como-fazer-hash-de-passwords_safesafesafesafety_passwords
– Franchesco