-1
I just logged in user, deleted the user himself logged in to the system, it turns out that instead of being redirected out of it I’m still in it.
What I did?
1 - I went to the Delete Employee page.
2 - I chose myself, the form redirected me to another page that made the exclusion
3 - On this exclusion operation page redirects me to the page listing all employees
4 - I was supposed to be redirected outside, but I’m still in the system
This is the excerpt from my code $_SESSION
that controls the permanence of the user on the system, if there is any way to improve it would be great (this excerpt is on all pages of my system.
<?php
require(__DIR__ . '/conexao/conexao.php');
require(__DIR__ . '/classe/classe_usuario.php');
session_start();
if((isset($_SESSION['id_usuario'])) && (!empty($_SESSION['id_usuario']))){
echo "Olá " . $_SESSION['nome_usuario'] . "!";
} else {
echo "<script> alert('Ação inválida, entre no sistema da maneira correta.'); location.href='/web/index.php' </script>";
die;
}
?>
// Page that deletes and redirects to the user listing page
<?php
require_once '../conexao/conexao.php';
require_once '../classe/classe_usuario.php';
session_start();
if(isset($_SESSION['id_usuario']) && isset($_SESSION['nome_usuario'])){
echo "Olá " . $_SESSION['nome_usuario'] . "!";
} else {
echo "<script> alert('Ação inválida, entre no sistema da maneira correta.'); location.href='/web/index.php' </script>";
die;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> DELETE | FUNCIONÁRIO </title>
<link rel="stylesheet" href="/web/css/css.css">
</head>
<body>
<?php
if(isset($_POST['Deletar'])){
$cd_funcionario = $_POST['cd_funcionario'];
try {
$remove = "DELETE FROM funcionario WHERE cd_funcionario = :cd_funcionario";
$remocao = $conexao->prepare($remove);
$remocao->bindValue(':cd_funcionario',$cd_funcionario);
$remocao->execute();
// Retorna para a pagina de formulario de listagem
header('Location: ../form_crud/form_select_funcionario.php');
} catch (PDOException $falha_remocao) {
echo "A remoção não foi feita".$falha_remocao->getMessage();
die;
} catch (Exception $falha) {
echo "Erro não característico do PDO".$falha->getMessage();
die;
}
} else {
echo "Ocorreu algum erro ao finalizar a operação, refaça novamente a operação.";
echo '<p><a href="../form_crud/form_delete_funcionario.php" title="Refazer operação"><button>Refazer operação</button></a></p>';
exit;
}
?>
</body>
</html>
This excerpt is on every page of my system, I need to do something in my file that makes deleting the employee to work?
– Milaanos