Error getting id in php

0

I have a web application and it has a registration and a login, I have two headers for one to show when the user has not logged in and another for when it is already logged. but when I try to take data from the array to put it in an input of type hidden I get an error

    <?php session_start();

require_once "views/extras/header.php";
require_once "views/extras/header-log.php";


if (isset($_SESSION['usuario'])) {
    header('Location: index.php');
}

$errores = '';

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $email = filter_var(strtolower($_POST['email']), FILTER_SANITIZE_STRING);
    $password = $_POST['password'];
    $password = hash('sha512', $password);

    try {
        $conexion = new PDO('mysql:host=localhost;dbname=empleos', 'root', '');
    } catch (PDOException $e) {
        echo "Error:" . $e->getMessage();;
    }

    $statement = $conexion->prepare('
        SELECT * FROM userslog WHERE email = :email AND password = :password'
    );
    $statement->execute(array(
        ':email' => $email,
        ':password' => $password
    ));

    $resultado = $statement->fetch();
    if ($resultado !== false) {
        $_SESSION['usuario'] = $resultado;
        header('Location: index.php');
    } else {
        $errores .= '<li>Datos Incorrectos</li>';
    }
}

require 'views/login.php';

require_once "views/extras/footer.php"; 
?>

that's my login code

and this is the link of all my project

    
asked by Cesar Gutierrez Davalos 29.04.2017 в 19:05
source

1 answer

0

Instead of sending the index, send to the dashboard
header('Location: dasboard.php');

In the dashboard in the first line you put something similar like that

<?php
include 'session_star.php';
?>

In my case it is session_star.php yours can be index.php since this file allows me to check if there is an active session, I have the following

session_start();
if (!isset($_SESSION['idusuario'])) {
  header('Location: login-turista.php');
die();

} and there you can send that if the session does not exist you return to the login..saludos

    
answered by 29.04.2017 в 19:18