doupingmao1903 2013-06-15 11:45
浏览 296

如何限制用户在具有不同用户类型的同一浏览器上的多个窗口上登录

The login page and their functionality works fine, but now I got a problem, when the user logged in with one account and after login he/she open new window on same browser and type the loginviewcontroller.php it is not showing the previous loggedin.php page and user can login with different accounts on two windows at the same time.

How can I restrict the user to login on multiple windows?

I need the functionality like gmail, if the user logged in once in a browser when he /she open new window on same browser and type the www.gmail.com it shows the logged-in user information ... but not the gmail login page...

Please help me fix this problem.

Here is the loginviewcontroller code

<?php

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

if (!isset($_POST['submit'])) {
    /// HTML code for login page....
} else {
    /// Here the values are posting...

    $Username  = $_POST['uname'];
    $Password  = $_POST['pwd'];
    $User_Type = $_POST['type'];
    session_start();

    If (!(empty($Username) && empty($Password) && empty($User_Type))) {

        $model = new UsersModel();

        $rowsCount = $model->checkUser($Username, $Password, $User_Type);

        if ($rowsCount != 0) {
            $_SESSION['user'] = $Username;

            header("location:loggedin.php");

        } else {
            echo '<script type="text/javascript">alert("Enter username and password correctly");
              window.location.href="LoginViewController.php";</script>';
        }
    }

   }
    ?>

Here is the loggedin.php code

<?php

session_start();
$_SESSION['logged_in'] = 'true';

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>"';
?>
  • 写回答

2条回答 默认 最新

  • dsasd12314 2013-06-15 11:48
    关注

    You are setting a variable in the user's session. You can just not allow the user to login again when this variable is set, since he'll be already logged in.

    Also, don't forget to call session_start(). i.e. you can put this at the very top of your login page:

    session_start();
    if (isset($_SESSION['user']))
      header("location:loggedin.php");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程