problem with Session start

Asked

Viewed 244 times

0

I am creating a login system with session to register. I believe this is ok.

It is recording well in the database; The e-mail confirmation is working perfectly and the login too, but when I try to create a session to protect my system, error appears HTTP ERROR 500, do not know what I’m doing wrong, below follows my code:

    <?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 you should direct the page after the login. I deleted part of the content to save space.

Can anyone help me find my mistake? 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>
  • 1

    Remove echo "Falha". $e->getMessage(); or add ini_set('display_errors', 'on'); at the beginning of both files.

  • Check whether in your php.ini the value is session.save_handler = files

No answers

Browser other questions tagged

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