-1

问题是当用户在该用户尝试在它接受的同一浏览器中使用相同/不同的凭据再次登录后登录时...

我不知道我哪里做错了。。

这是 login.php

      <?php

    header("Cache-Control: private, must-revalidate, max-age=0");
    header("Pragma: no-cache");
    header("Expires: Fri, 4 Jun 2010 12:00:00 GMT");

     include('GenericClasses/GenericCollectionClass.php');
      include('Models/UsersModel.php');
      include('DataObjects/Users.php');
      include('DatabaseAccess/DBHandler.php');

      session_start();

      if(!isset($_SESSION['user']))
  {
   header('Location: LoginViewController.php');
     exit();
   }
   echo '"<div style="background:white; text-align:right"> Login as:'.$_SESSION['user'].'
   <a href="LogoutViewController.php" style="text-align:right">Logout</a></div>"';
    $username=$_SESSION['user'];
    $model = new UsersModel();

    $result = $model->checkUserid($username);
     $_SESSION['id']=$result;
    echo '<div style="background:white; text-align:right;">'.$_SESSION['id'].'</div>';

    ?>

任何建议都会被接受...

4

1 回答 1

0

我得到了我的问题的答案......

这是基于 LoginViewController.php 中的 session[user] 重定向用户的代码,它工作正常..

1) 始终将 session_start() 放在代码的顶部...

    <?php
       session_start();

          include('GenericClasses/GenericCollectionClass.php');
          include('Models/UsersModel.php');
          include('DataObjects/Users.php');
          include('DatabaseAccess/DBHandler.php');
           if(!empty($_SESSION['user']))
           {

             header("Location:loggedin.php");
           die();
           }
           else 
          {
        ?>
         //Html code for login page
        <?php
          }
             ?>

这是 Loggedin.php 代码..

              <?php
                    session_start();
              header("Cache-Control: private, must-revalidate, max-age=0");
              header("Pragma: no-cache");
              header("Expires: Fri, 4 Jun 2010 12:00:00 GMT");

               include('GenericClasses/GenericCollectionClass.php');
               include('Models/UsersModel.php');
               include('DataObjects/Users.php');
               include('DatabaseAccess/DBHandler.php');


        if(!isset($_SESSION['user']))
      {
       header('Location: LoginViewController.php');
        exit();
        }
         echo '"<div style="background:white; text-align:right"> Login as:'.$_SESSION['user'].'
     <a href="LogoutViewController.php" style="text-align:right">Logout</a></div>"';


      ?>
于 2013-07-02T07:13:52.303 回答