Php 为什么我的会话在页面重定向中丢失?

Php 为什么我的会话在页面重定向中丢失?,php,session,session-variables,session-cookies,Php,Session,Session Variables,Session Cookies,我知道这又是一个同样的问题,但是我尝试了所有的方法并排除了故障,但没有弄明白为什么在这种情况下我会出错 提前谢谢 loginpage.php <?php include('crud.php'); // code if($_POST['login']=='ok'){ $r=base::login($_POST); if($r==true) { var_dump($_SESSION['lo

我知道这又是一个同样的问题,但是我尝试了所有的方法并排除了故障,但没有弄明白为什么在这种情况下我会出错

提前谢谢

loginpage.php

<?php 
   include('crud.php');
   // code
    if($_POST['login']=='ok'){      
        $r=base::login($_POST);
        if($r==true)
        {
            var_dump($_SESSION['login']); // here I am getting the session it on the same page 
            header("location: index.php");
            die();
        }
        else
        {
            $msg="Username or Password is Incorrect";
        }
    }
    // code
?>
<?php
@ob_start();
@session_start();
ini_set('error_reporting',1);
// db call
// other functions
$_SESSION['login']=$sql->id; // here session is created
return is_numeric($sql->id)? true :false;

?>

index.php

<?php 
include('crud.php');
// code

var_dump($_SESSION['login']);  // here its lost

// code
?>

crud.php

<?php 
   include('crud.php');
   // code
    if($_POST['login']=='ok'){      
        $r=base::login($_POST);
        if($r==true)
        {
            var_dump($_SESSION['login']); // here I am getting the session it on the same page 
            header("location: index.php");
            die();
        }
        else
        {
            $msg="Username or Password is Incorrect";
        }
    }
    // code
?>
<?php
@ob_start();
@session_start();
ini_set('error_reporting',1);
// db call
// other functions
$_SESSION['login']=$sql->id; // here session is created
return is_numeric($sql->id)? true :false;

?>

在一个文件中使用$\u会话['loginId'],在其他文件中使用$\u会话['login']


您还可以使用var_dump($_SESSION)查看$_SESSION数组的所有元素。

代码对我来说运行良好。即使在一个文件中使用了$_SESSION['loginId']之后,$_SESSION全局数组中仍然可以使用'login'键。因此,在index.php中,它会回显“login”键值b'z,因为它是在crud.php中设置的。

您遇到了什么错误?