Why do I get ERR_TOO_MANY_REDIRECTS?

1

I was working with a web that I'm doing, it has a kind of login and this error appeared, I redirect them with header.
This page does not work The mivhost.com page has redirected you too many times. Delete cookies ERR_TOO_MANY_REDIRECTS

<?php
if (isset($_POST['input-login'])) {
    if ($_COOKIE['contraE']<3) {
            $usuario=$_POST['input-usuario_txt'];
            $password=$_POST['input-password_txt'];
            $verifica=new Verificador();
            $cantidadVacios=$verifica->hayVacios($usuario,$password);
            if ($cantidadVacios>0) {
                echo "<div class=\"div-mensajeSuscripcion\">";
                echo "<p class=\"texto-error\">Los datos de los campos no deben estar vacios</p>";
                echo '</div>';
            }
            else {
                $consulta=new Consulta('administradores');
                $resultado=$consulta->loginEncriptado($usuario,$password);
                if($resultado>0){
                    session_start();
                    $_SESSION['usuario']=$usuario;
                    header('location:edicion.php');
                }else {
                    echo "<div class=\"div-mensajeSuscripcion\">";
                    echo "<p class=\"texto-error\">Tu usuario o contraseña son invalidas</p>";
                    if(isset($_COOKIE['contraE']))
                    {setcookie('contraE',$_COOKIE['contraE']+1,time()+604800);}
                    else{setcookie('contraE',1,time()+604800);}
                    echo '</div>';
                }
                $consulta->cerrarConsulta();
            }
    } else {
    echo "<div class=\"div-mensajeSuscripcion\">";
        if ($_POST['input-password_txt']=='perdonmeequivoque') {
        echo '<p class="texto-error">estamos reiniciando tu clave para que puedas volver intentarlo</p>';
        setcookie('contraE',1,time()-1);
        }else {
            echo '<p class="texto-error">Ya has tenido hecho muchos intentos</p>';
        }
    echo '</div>';
    }    
} else {
    session_start();
    if (isset($_SESSION['usuario'])) {
        header('location:edicion.php');
    }
}

It's just php but I put python because I think the error is not from the php code before it worked for me now, esque does not work for me

thank you very much for trying to help me

    
asked by Israel David Villarroel Moreno 23.08.2018 в 10:28
source

2 answers

2

Although it can certainly be the code and the suggestion of fedorqui it is better that you bear in mind, that has happened to me on a couple of occasions.

One of the times was because Apache's mod_security was active, and one of the rules did not allow me to call the same script from the same script several times, depending on what could be a security breach and I had to review how organize that. The problem may be in the mod_security, you can try to deactivate it and see what happens, but it is not advisable, if it is that, it is better to know why it is bothering you.

But the most common situation that I have had in that type of case, is that if the server has cpanel, I have never managed to correctly work the options that the same cpanel brings, which help to redirect the http to https, only I managed once and tried to replicate to the other servers, without any favorable result, then touched the old one, disable the redirection function from cpanel, and do it with a .htaccess file from the public directory of the website.

Although it may be something from the browser, the only thing I see in the code, which is redirecting, is

header('location: edicion.php')

To be sure it is better to put "Location", with L, although I read that the specification says that it is not necessary and I have not found anything about browsers that can be set to "case" (uppercase or lowercase).

The other thing is that what they say in the comments is true, but I'm going more for the part of, what does python have to do with? I only see code in php.

And the other thing, will there be something wrong with the code in the edicion.php file, which causes it to be returned to the login file?

    
answered by 23.08.2018 / 18:57
source
1

Thanks to everyone I already solved the problem I realized it was because I was doing an infinite redirection from my website without wanting to This error is usually due to redirections without stopping from one website to another

    
answered by 23.08.2018 в 22:43