2
Well folks, after a long search on google, I found nothing similar to my problem, so I thought to report here.
Yesterday a system I am 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 happened, I was writing a pagination system and had logged into a login account to do some basic tests. Now every time I try to open the main page where the user type the password to log in appears "This web page has a redirect loop".
I tried some diagnostic suggested by Chrome, but nothing worked. I also deleted all code until the moment I know the system was working, but it also didn’t work.
Someone’s been through this before?
Here’s a piece of the code
Connection to the connected database
//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');
}
Pagina principa, principal.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>
Hello @Vandro-Auro, Welcome to Stack Overflow! If possible, post parts of your code so we can better assist you. You can start by taking a look at the places where you redirect to see if there is a bug that might be doing this (for example, a page that redirects to another page in an infinite loop due to a validation failure)
– MateusDemboski
Put the code that checks the login. The part that checks the login session. It’s 90% sure the loop is in that snippet.
– Daniel Omine
bingo.. that’s it.. connection_sessao.php shouldn’t be included that way.
– Daniel Omine
@Danielomine why?
– Jorge B.
Try trading all include for include_once
– SneepS NinjA