Alert message in SESSION

Asked

Viewed 569 times

0

I have a system that works perfectly on the computer(A) that was developed and, when passing to the computer(B) server with the same settings, the same version of Easyphp and etc, presented many, but many errors.

One of these errors is right in the login and says:

"Notice: A Session had already been Started - ignoring session_start() in (directory/logica-user.php) on line 4."

This is the logica-user.php:

<?php
session_start();
function verificausuario(){
    if (!isset($_SESSION["usuario_logado"])) {
    header("location: login.php");
    die();
   }
}
function verificausuario() {
    if(!isset($_SESSION["usuario_logado"])) {
    header("location: login2.php");
    die();
   }
}
function logaUsuario($nome) {
    $_SESSION["usuario_logado"] = $nome;
}
function logout() {
    session_destroy();
}

?>

Line 4 is this session_start(); but there is nothing wrong with it, after all, it is this whole bugged system is the same system that runs perfectly on the computer(A) and ran on the computer(B) before it is formatted.

  • 1

    This page must be included in another 2 or more times... usually this error comes from using include / require try to replace them respectively to include_once / require_once

  • Maybe you included in the document another page that had already given a session_start, the PHP triggers this warning to alert you, if you want to fix this, review the logic and get them out of where you don’t need them, ultimately put a @ in front of the session_start to hide the Warning.

1 answer

0


It worked when I did it:

<?php
if(!isset($_SESSION)) {
    session_start();
}
function verificausuario(){
    if (!isset($_SESSION["usuario_logado"])) {
    header("location: login.php");
    die();
   }
}
function verificausuario() {
    if(!isset($_SESSION["usuario_logado"])) {
    header("location: login2.php");
    die();
   }
}
function logaUsuario($nome) {
    $_SESSION["usuario_logado"] = $nome;
}
function logout() {
    session_destroy();
}

?>

Browser other questions tagged

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