doucheng5705 2013-06-28 08:16
浏览 27
已采纳

如何使用php防止在同一浏览器中多次登录

It's php session problem.. where user's can login multiple times.. on same browser with same/different credentials..

1) User1 logged in ..

2) User1 Try to open LoginIndex.php in new tab..

3) It's showing the LoginIndex.php page instead of Previous Logged in page(User1 logged in)...

4) Accepting the User1 to login again with same/different credentials.. in same browser

I don't know why it is taking the login values again..

Here is the snippet of LoginViewController.php

           <?php        

       if (!isset($_POST['submit'])) 
     {


       ?>
            <html>

        <table align="center">
              <tr>

                 <td>
                    <input  class="input" type="text" name="uname" id="uid"  placeholder="Username"  >
                </td>
             </tr>
             <tr>

                <td>
                    <input  class="input" type="password" name="pwd" id="pid" placeholder="Password" >
                </td>
            </tr>

              <tr>
                <td> <input type="submit"  name="submit" value="" > </td>
            </tr>
      </table>

     <?PHP 

      }        

      else
   {

//If you are submitting the form insert the details into database

       $Username = $_POST['uname'];
          $Password = $_POST['pwd'];

            session_start();



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

      $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 logged-in.php code that what i am working on it...

       <?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>"';


      ?>

Any suggestions are acceptable...

  • 写回答

3条回答 默认 最新

  • douhuocuo9012 2013-06-29 10:35
    关注

    In the loginController you need to check if session variable is set.If so then redirect the user to the member page or similar..

    This might work

    <?php
    session_start();
    if(!empty($_SESSION['username']))
    {
        header("location : member.php");
        die();
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行