Error 404 in a php file

0

I'm trying to make a form, created in the index.php file, which sends by POST method to the cadastro.php page and with a header() I send a check variable back to the index .

However, when it returns to the index.php page, it says that the file was not found and gives Error 404 .

index.php :

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Exercicio 1</title>
</head>
<body>
<?php
    echo '<form action="cadastro.php" method="post">
            Nome: <input type="text" name="nome" value="" /> <br />
            Email: <input type="text" name="email" value="" /> <br />
            Senha: <input type="password" name="senha" value="" /> <br />
            <input type="submit" value="Enviar" />
        </form>';

    if(@$_GET['login'] == 1){
        echo 'Informe nome novamente!';
    }

?>
</body>
</html>

cadastro.php :

<?php
require 'connection.php';
require 'database.php';

$usuario = array(
    'nome' => $_POST['nome'],
    'email' => $_POST['email'],
    'senha' => $_POST['senha'],
    );

if(empty($_POST['nome']) || strlen($_POST['nome']) < 5){
    header("Location:index.php login=1");
}
else if(!strstr($_POST['email'], '@') || strlen($_POST['email']) < 5){
    header("Location:index.php login=2");
}
else if(empty($_POST['senha']) || strlen($_POST['senha']) < 5){
    header("Location:index.php login=3");
}
else{
    DBCreate('usuarios', $usuario);
    header("Location:index.php login=4");
}  ?>

I'm using XAMPP on Windows.

    
asked by anonymous 13.07.2017 / 17:59

1 answer

2

The addresses are incorrect:

header("Location:index.php login=1");
...
header("Location:index.php login=2");
...
header("Location:index.php login=3");
...
header("Location:index.php login=4");

Switch By:

header("Location:index.php?login=1");
...
header("Location:index.php?login=2");
...
header("Location:index.php?login=3");
...
header("Location:index.php?login=4");

Note that Location is an HTTP header header, ie it is not PHP that redirects, but the browser when receiving the headers, so location: must contain a relative or absolute path to the current page address.

About the use of at:

I noticed that you are using @ to suppress the warnings, in case it would be nice to read this:

13.07.2017 / 18:18