限制多个用户在同一浏览器中使用相同/不同的凭据登录

时间:2013-06-27 04:28:15

标签: php login login-control

问题是用户在该用户尝试使用相同/差异凭据在同一浏览器中再次登录后登录...

我不知道我哪里出错了。

这是loggedin.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>';

    ?>

任何建议都是可以接受的......

1 个答案:

答案 0 :(得分: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>"';


      ?>
相关问题