0
My login system is not working...
In my project I have a file called header.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 this link by include on all pages...
My menu contains in the upper right corner a button to open the login form.
And the menuprincipal.php has the following code:
<?php
if(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 there is open user session, the system gives a include in the file that contains user profile. If there is no session it gives a include in the file that has login form.
Until then the login works! However, when accessing another page, the user is logged. It’s like the session is over.
But being that mine logout.php is under 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 friends, I am a beginner and I confess that I read it long before asking, but I find it difficult to understand this process. I count on your cooperation.
P.S. An important observation is that... this error happens only with the project that is hosted on the web, and in LOCALHOST works perfectly.
Open session_start(); in all the files you see check the existence of sessions, I think that’s it, good luck!
– Diego Ananias
What hosting service do you use? , have some server rules that you need to configure
– MarceloBoni