problem with session start

0

I am creating a login system with session to register. I think it's okay.

It is writing well to the database; The confirmation email is working perfectly and login too, but when I try to create a session to protect my system, the HTTP ERROR 500 error appears, I do not know what I'm doing wrong, here's my code below:

    <?php
session_start();

    if (isset($_SESSION['usuario'])){
    header("Location: inicio.php");
    die();

$host = "mysql:dbname=blackhost;host=localhost";
$user = "zn9inf7futpl";
$pass = "[aG$|Qxd1R";

    try {
        $pdo = new PDO($host, $user, $pass);
    } catch (PDOException $e) {
        echo "Falha". $e->getMessage();
    }

$usuario = addslashes($_POST['email']);
$senha = md5(addslashes($_POST['senha']));

$sql = $pdo->query("SELECT * FROM hostel WHERE status='1' and email='$usuario'  and senha='$senha'");

if($sql->rowCount() > 0) {
    $_SESSION['usuario'] = true;
    header("Location: inicio.php");

}else{
    echo "<script>alert('Usuario ou senha inválidos. Ou você ainda nao confirmou o seu cadastro por email.')</script>";
}
?>

And this part below, is where to turn the page after the login. I deleted some of the content to save space.

Can anyone help me find my error? Please.

    <!DOCTYPE html>
<?php
session_start();

    if(!isset($SESSION['usuario'])){
    header("Location: index.php");
    session_destroy();
    }

?>

<html lang="en">


  <body>
  <!-- container section start -->
  <section id="container" class="">
      <!--header start-->

     <?php require_once('header.php'); ?>
         <?php require_once('menu.php'); ?>

      <!--sidebar end-->

      <!--main content start-->
      <section id="main-content">
          <section class="wrapper">
          <div class="row">
                <div class="col-lg-12">
                    <h3 class="page-header"><strong>Inicio</strong></h3>
                    <ol class="breadcrumb">

                    </ol>
                </div>
            </div>
              <!-- page start-->
           <p align="center"> <img src="imangens/maos.png" width="15%" /></p><br>
<h1 align="center">Vamos jutos proteger-nos, juntos podemos nos ajudar e evitar fraudes </h1><br>

                      <!-- page end-->
          </section>
      </section>
      <!--main content end-->
      <div class="text-right">
            <div class="credits">
             [email protected]

            </div>
        </div>
  </section>
  <!-- container section end -->
    <!-- javascripts -->
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- nice scroll -->
    <script src="js/jquery.scrollTo.min.js"></script>
    <script src="js/jquery.nicescroll.js" type="text/javascript"></script><!--custome script for all page-->
    <script src="js/scripts.js"></script>


  </body>
</html>
    
asked by anonymous 29.01.2018 / 16:57

0 answers