简体   繁体   中英

Redirect to either login page or lock page on session time

Thank you in advance for any one who comes in to my rescue

Case:

I have a login page that users for my system use to login, after loginnng in, they are entitled to an idle moment for about 10 minutes, after that they are redirected to the login page again to enter their details.

Needed:

Am trying to implement a redirect to the other page which is the lock page where the user will only enter password without entering his username but this is really giving me headache because when the session is destroyed, the user's credentials are all cleared hence requiring him/her to enter both the username and password. Is there any way i can store the user's username when the session is timed out so that its echoed in a hidden field on the lock screen.

Am trying to implement this with php

Login.php //On Load

 <?php if(isset($_SESSION['UserName'])) { ?> <style> username { display:none; } </style> <script> docuemnt.GetElementById("username").value = <?php echo $_SESSION['UserName']; ?> </script <?php

//After Login

$_SESSION['UserName'] = $username;
$_SESSION['Login'] = 'True';
$_SESSION['Time'] = time();

Make in every page this code

$time = $_SESSION['Time'];
$time_check=$time-600;
if($time<$time_check) {
  $_SESSION['login'] = 'False';
  header(location:login.php);

您可以通过在url中添加用户名并使用$ _GET变量将其提取到该页面上来执行此操作。在销毁会话之前,将用户名从会话变量存储到另一个变量中,并将其放在url中。

let me correct you here dude,

working version:

  $time = $_SESSION["time"];
  $time_check = $time + 5;
  if(time() > $time_check)
  {
    $_SESSION["logged"] = "False";
    header("Refresh: 1; url=lockscreen.php");
  }

and you forgot the "" in header

不要破坏会话,只需取消设置所需的用户数据即可,而不要取消用户名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM