I get an error when logging

0

The error that it gives me is when trying to access apanel.php sometimes it accesses and sometimes it does not, I think it's thing of the sessions but I'm not sure.

PHP:

<?php
session_start();
        include("cabecera.php");
        include("conexion.php");

    if (isset($_REQUEST['Enviar'])) {
    $usuario = $_REQUEST['ausuario'];
    $password = $_REQUEST['apass'];

    $sql = $conexion->query("SELECT * FROM usuarios,apass WHERE ausuario='".$usuario."' and apass='".$password."'");
    while ($login = $sql->fetch_assoc()) {
        $usuarioDB = $login['ausuario'];
        $passwordDB = $login['apass'];
    }
    if ($usuario == isset($usuarioDB) && password_verify($password, $passwordDB)) {
        $_SESSION['loggedin'] = "loggedin";
        $_SESSION['ausuario'] = $usuarioDB;
        $_SESSION['apass'] = $passwordDB;
        header("Location: apanel.php");
    } elseif ($usuario !== isset($usuarioDB)) {
        echo "<div class='error'><span>El Nombre de Usuario que has Introducido es Incorrecto</span></div>";
    } elseif (password_verify($password, $passwordDB) === FALSE) {
        echo "<div class='error'><span>La Contraseña que has Introducido es Incorrecta</span></div>";
    }
}
?>

HTML:

<form id="login-form" class="text-left" method="post">

<br/>

<tr>
                <td><span class="fa-user"></span><input name="ausuario" placeholder="usuario" type="text" onfocus="clearText(this)" onblur="learText(this)" class="textfield"/><br/><br/></td></tr>

<tr>
<td><span class="fa-lock"></span><input name="apass" placeholder="contraseña" type="password" onfocus="clearText(this)" onblur="clearText(this)" class="textfield"/><br/><br/></td></tr>

        <input type="checkbox" id="lg_remember" name="lg_remember"><label for="lg_remember">recordar</label><br/>
                                        <tr><td><input id="submit" type="submit" name="submit" value="Enviar">
    
asked by Raul 21.03.2018 в 15:56
source

1 answer

0

in <form id="login-form" class="text-left" method="post"> test with replace

<form action="<?php echo $_SERVER['PHP_SELF'];?>" class="text-left" method="post" href="#" >
  

PHP_SELF is a variable that returns the current script that is being   running This variable returns the name and path of the file   current (from the root folder). You can use this variable in the field   of the FORM.

Using the variable PHP_SELF you can write a more generic code that can be used on any page and you do not need to edit the action field

    
answered by 23.03.2018 в 00:01