Well folks, after a long search on google, I did not find anything similar to my problem, so I thought I'd report it here.
Yesterday a system I'm building started displaying this problem "This web page has a redirect loop". The server I'm using is XAMPP and the browser is Chrome.
At the time the problem occurred, I was writing a paging system and had logged a login account to do basic tests. Now every time I try to open the main page where the user type the password to login appears "This webpage has a redirect loop".
I tried some diagnostics suggested by Chrome, but nothing worked. I also deleted all the code until the time I know the system was working, but it also did not work.
Has anyone gone through this before?
Here is a piece of code
Connection to database connection_session.php
//Seleciona o banco de dados
$hostname = "localhost";
$username = "root";
$password = "";
$database = "sessao";
// as variáveis email e senha recebem os dados digitados na página anterior
$email = (isset($_POST['Email'])) ? $_POST['Email'] : $_SESSION['Email']; // se n tiver post, utiliza sessao
$senha = (isset($_POST['Senha'])) ? $_POST['Senha'] : $_SESSION['Senha']; // se n tiver post, utiliza sessao
//Conexão mysql
$conexao = mysql_connect($hostname, $username, $password) or die ("Erro na conexão do banco de dados.");
//Conexao com banco de dados
$selecionabd = mysql_select_db($database,$conexao) or die ("Banco de dados inexistente.");
//Comando SQL de verificação de autenticação
$tabela = "SELECT * FROM usuarios WHERE Email = '$email' AND Senha = '$senha'";
$resultado = mysql_query($tabela,$conexao) or die ("Erro na seleção da tabela.");
//Caso consiga logar cria a sessão
if (mysql_num_rows ($resultado)) {
$_SESSION['Email'] = $email;
$_SESSION['Senha'] = $senha;
}
//Caso contrário redireciona para a página de autenticação
else{
//Destrói
session_destroy();
//Limpa
unset ($_SESSION['Email']);
unset ($_SESSION['Senha']);
//Redireciona para a página de autenticação
header('location:principal.php');
}
Home page, main.php
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Pagina Pricipal</title>
</head>
<body>
<?php include "conexao_sessao.php"; ?>
<form method="post" action="profile.php" >
<label>E-mail: </label>
<input type="text" name="Email" id="Email" /><br />
<label>Senha:</label>
<input type="password" name="Senha" id="Senha" /><br />
<input type="submit" value="Login" />
<a href= "novo_usuario.php">Cadastre-se</a>
</body>
</html>
Page that opens after the user logs in, profile.php
<!DOCTYPE html>
<?php include "conexao_sessao.php";
if(isset($_GET['logout'])) {
//Destrói
session_destroy();
//Limpa
unset ($_SESSION['login']);
unset ($_SESSION['senha']);
//Redireciona para a página de autenticação
header('location:principal.php');
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<body>
<head>
<meta charsert="UTF-8"/>
<title>Sistema de Comentários</title>
</head>
<a href="principal.php?logout=1">Sair</a>
</br>
</br>
<a href="responda.php">Clique aqui para responder perguntas!</a>
</br>
<a href="EditandoPerfil/editar_perfil.php">Editar Perfil!</a>
<hr>
</br>
<h3>Perguntas Respondidas</h3>
</br>
<hr>
<?php include("RespondaGlobal/mostrar.php"); ?>
</body>
</html>