Avoid access to the log

0

What can I do if I am making a web page and I want to avoid that when the session is started it allows access to the log, but it throws me an error?

Log code

<head>
    <meta charset="UTF-8">
    <title>Frutillas</title>
</head>

<body>
   <?php
session_start();
if ($_SESSION["sessionOK"]=="si"){
    header('location:exclusivoSesion.php');
}
?>
<form action="comparacion.php" method="post">

        Correo Electronico:
    <input type="email" name="email" required>

    <br>
    <br>

    Contraseña:
    <input type="password" name="password" required>

    <br>
    <br>

    <input type="submit" value="Enviar">

</form>

</body>

Comparison.php

<?php
$email = filter_input(INPUT_POST, 'email');
$contrasena = filter_input(INPUT_POST, 'password');

include ('acceso.php');

$sql = "select password from usuarios where email='".$email."';";
$sql2 = "select nombre from usuarios where email='".$email."';";

$resultado = $dp->query($sql);
$nombre = $dp->query($sql2);

$row = $resultado->fetch_assoc();
$row2 = $nombre->fetch_assoc();

if ($row['password'] == $contrasena) 
{
    session_start();
    $_SESSION["sessionOK"]="si";
    $_SESSION["correo"]=$email;
    $_SESSION["nombre"]=$row2['nombre'];
    header ('location:exclusivoSesion.php');
} 
else {
    echo 'usuario o contraseña incorrecta';
    echo '<a href="login.php">Ir a login</a>';
}
mysql_free_result($resultado);
mysqli_close($dp);

? >

    
asked by Alan 06.06.2018 в 05:24
source

1 answer

0

You must first validate that the index of the session exists, isset() is to validate that the variable exists and empty() is to validate that it is not empty. Your problem is that you are trying to invoke a session that may not exist.

Review the isset () function here

Check the empty () function here

<head>
    <meta charset="UTF-8">
    <title>Frutillas</title>
</head>

<body>
   <?php
session_start();
if ( isset( $_SESSION["sessionOK"] ) && !empty( $_SESSION["sessionOK"] ) ){
    if( $_SESSION["sessionOK"] == 'si' ){
          header('location:exclusivoSesion.php');
    }
}
?>
<form action="comparacion.php" method="post">

        Correo Electronico:
    <input type="email" name="email" required>

    <br>
    <br>

    Contraseña:
    <input type="password" name="password" required>

    <br>
    <br>

    <input type="submit" value="Enviar">

</form>

</body>
    
answered by 06.06.2018 / 06:29
source