My login system is not working ...
In my project I have a file called cabecalho.php
<?php
ob_start(); //abrir sessao
session_start();//iniciar sessao
error_reporting(0); //ignorar alguns erros
include("Pdo/conexao.php"); //conexao com banco de dados
include("includes/logout.php"); //arquivo pra delogar usuario
?>
<!DOCTYPE html>
<html> ...
This header.php is linked by include on all pages ...
My menu contains a button in the upper right corner to open the form.
Andmenuprincipal.phphasthefollowingcode:
<?phpif(isset($_GET['acao'])){if(isset($POST['logar'])){$acao=$_GET['acao'];if($acao=='negado'){header("Location: login.php?acao=acessonegado");
}
}
}
//se EXISTIR usuario e senha logados
if(isset($_SESSION['USUARIOCFSITE']) && (isset($_SESSION['SENHACFSITE']))){
include 'includes/usuariologado.php';
}else{
if(isset($_POST['logar'])){
$usuario = trim(strip_tags($_POST['usuario']));
$senha = trim(strip_tags($_POST['senha']));
if ($usuario == "admin" and $senha == "123123") {
//recuperar o POST (oq usuario digitou)
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$_SESSION['USUARIOCFSITE'] = $usuario;
$_SESSION['SENHACFSITE'] = $senha;
include 'includes/usuariologado.php';
}else{
include 'includes/usuariodesconectado.php';
}
}else{
include 'includes/usuariodesconectado.php';
}
}
?>
My logic is: if an open user session exists, the system will include an include in the file that contains the user's profile. If the session does not exist, it will include an include in the file that has a login form.
Until then login works! However, when accessing another page, the user is logged out. It's like the session ends.
But my logout.php is about the condition of a request!
<?php
if (isset($_REQUEST['sair'])) {
session_destroy();
session_unset( $_SESSION['USUARIOCFSITE'] );
session_unset( $_SESSION['SENHACFSITE'] );
header("Location: login.php?acao=logout");
}
?>
My dear, I am a beginner and I confess that I read a lot before asking, but I find it difficult to understand this process. I count on your cooperation.
P.S. An important note is that ... this error happens only with the project that is hosted on the web, and in LOCALHOST works perfectly.