0
<?php
   include("config.php");
   session_start();

   if($_SERVER["REQUEST_METHOD"] == "POST") 
   {
      $myusername =$_POST['txtUserName'];
      $mypassword = $_POST['txtPassword']; 
      $sql      = "SELECT id FROM admin_login WHERE username = '$myusername' and password = '$mypassword'";
      $result   = sqlsrv_query($conn,$sql);
      $count    = sqlsrv_has_rows($result);
      if($count == 1)
      {
         $_SESSION['login_user'] = $myusername;
         header("location:home.php");
      else
      {
        echo '<script language="javascript">';
        echo 'alert("Please Enter Your User Name And Password Correct")';
        echo '</script>';
      }
   }
?>

hare is my login code but i want to set session timeout include in same code . so any one can provide solution for this problem

Jigar7521
  • 1,549
  • 14
  • 27
Shivraj
  • 31
  • 5

2 Answers2

0

You could manipulate session lifetime within php runtime with some limits.

Take a look at this answer: How to change the session timeout in PHP?

A more simpler way coul be record the time() when the user does the login. Then in the code you use to verify the login status check this time and reject the status if it's older than time() - Xseconds.

Community
  • 1
  • 1
0

Using htaccess file

#php_value session.cookie_lifetime 3600

#php_value session.gc_maxlifetime 3600

Using PHP

ini_set('session.gc_maxlifetime', 3600);

You can set session time out using above method and also you can get session time out value set in server using

ini_get('session.gc_maxlifetime')

may be this answer helpful for you

Ronak
  • 36
  • 5