سؤال

The problem is when the user logged-in after that user tries to login again with same/diff credentials in same browser it is accepting ...

I don't know where i kept wrong..

Here is the 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>';

    ?>

Any suggestions will be acceptable...

هل كانت مفيدة؟

المحلول

I got the answer for my question ....

Here is the code for the redirecting user based on the session[user] in LoginViewController.php and it's working fine..

1) Always place session_start() top of the code...

    <?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
          }
             ?>

Here is Loggedin.php code ..

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


      ?>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top