PHP codes register but do not log in

Asked

Viewed 244 times

1

I have 6 pages in PHP, two of them present me problems:

  • php entry. (where are the database connection data)
  • php client. (is the login page, only html formatting)
  • login.php (file that checks and logs in)
  • vip.php (is the page restricted to registered users)
  • php. (is a registration page, only html formatting)
  • register.php (file that checks and performs the registration)

The connection page php entry. is working, I say this because the registration system works perfectly (php. and register.php)

The problem is in logging in, it used to work normally, but after updating the styles (!) simply this part stopped working, I tried other codes, but I could not by my inexperience in php, follows the problematic codes (in parts):

vip.php - Page with the Session

    <?php
session_start();

if(!isset($_SESSION['documentoSession']) AND !isset($_SESSION['contratoSession'])){
    header("Location: cliente.php");
    exit;
}
   ?>

php client. - Who logs in, or should log in

   <?php

//Conexão com o banco de dados
include "entrada.php";

// Inicia a sessão
session_start(); 

//Dados preenchidos no formulário
$documento = $_POST['documento'];
$contrato = $_POST['contrato'];

//Comparação e validação dos dados
$sql_acesso = mysql_query("SELECT * FROM iAzulDataBase WHERE Documento = '$documento' AND Contrato = '$contrato'");

if(mysql_num_rows($sql_acesso) == 1){

    $_SESSION['documentoSession'] = $documento;
    $_SESSION['contratoSession'] = $contrato;
    include "iAzulVIP.php";

}else{

    unset($_SESSION['documentoSession']);
    unset($_SESSION['contratoSession']);
    include "cliente.php";
}
?>

php client. - html login code (because it is a private code, part was removed)

<html>
<head>
</head>  

<body class="metro" onLoad="setFocus()">


    <div class="total">
    <div class="pagina">
    <div class="logotipo">
    <h1><a href="#"><img src="Lion/Logotipo.png" alt="x" width="300px"></a></h1></div>
            <div class="acessorapido">
        <h2 class="text-info"><i class="fa fa-user-plus"></i>&nbsp;|&nbsp;Área do Cliente</h2>
        <h4 class="text-info">Acesse aqui sua página exclusiva x</h4></div><br>

    <div class="acessorapido">
    <div class="database_center">
        <form action="login.php" method="post">
        <fieldset><br>

            <strong>CPF ou CNPJ:</strong><br>
            <div class="input-control text size4">
            <input type="number" name="documento" id="documento" />
            </div><br>

            <strong>Nº do Contrato:</strong><br>
            <div class="input-control text size4">
            <input type="number" name="contrato" />
            </div><br>

            <div class="alinharbutao">
            <button type="submit" class="large button info" name="login">Acessar</button>
            </div><br>

        </fieldset>
        </form>

    </div></div><!--Fim do Formulário de Cadatro-->

</body>
</html>
  • The file login.php ? Enter the login form code

  • is named as.php input

  • Enter the login form code

  • Make a mistake ? what happens ?

  • put the code, no error appears, just back to the login screen, as you should do if the document or contract (user and password of this scheme) was wrong, but this is not the problem...

  • in.php client use session_start() at the beginning of the page, just below the php opening tag. I do not know if it will be the solution of the problem, but it is a good practice.

Show 1 more comment

1 answer

1


Do there a test where you put to give include if the login is successful take the include and put

echo "
<script>
    window.location = 'iAzulVIP.php';
</script>
";

See and tell the result

  • O.o Wow, it was the fastest problem I solved in life, man thank you very much, it was show...

  • Solved then ? that way ?

  • Just doubted why it worked before? the php server I changed from 5.4 to 5.3, to avoid any incompatibility

  • Solved, it is perfect everything else, including the logout system and if close the browser it "kills" the Session

  • It solved yes, by changing the code for what you put in the answer, that was the solution :D

  • mark the answer as certain

  • good continuation

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.