Session timeout

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samyphp
    New Member
    • Jul 2007
    • 3

    Session timeout

    dear friends...
    Can we set time for the session to expire..?
    If anybody know...plz send me the code...
  • henryrhenryr
    New Member
    • Jun 2007
    • 103

    #2
    Hello

    You need to check out this page:



    It has everything you need to know about sessions. I think you can use session.gc_maxl ifetime configuration option.

    You can also try:



    Which is a function to set the cookie parameters (so you can set it to expire as you would a cookie).

    Comment

    • unicorn
      New Member
      • Sep 2006
      • 23

      #3
      Originally posted by samyphp
      dear friends...
      Can we set time for the session to expire..?
      If anybody know...plz send me the code...

      here is link where you can find lots of examples.
      php.net
      but i recommend to use cookies and set expiration time read this

      or if you need high security and realibility, use your own 'expiration time', i.e. create cookie with value and its expirity date and compare it with datebase.

      something like that

      login.php ->
      [code=php]
      <?php

      $uID = uniqid("");
      $IPaddress = $_SERVER["REMOTE_ADD R"];
      mysql_query("UP DATE user SET uID='$uID',IPad dress='$IPaddre ss',date='".dat e("U")."' WHERE username='$user name'");


      setcookie("user name",$username );
      setcookie("uID" ,$uID);



      ?>
      [/code]
      check authentication ->
      [code=php]
      <?php

      function issesauth()
      {

      $usi = filter($_COOKIE['username']);
      $ida = filter($_COOKIE['uID']);

      $vaxkakoi = MYSQL_QUERY("SE LECT * FROM user WHERE username='$usi' AND uID='$ida' AND activ='Y'");
      $chachacha = mysql_fetch_arr ay($vaxkakoi);
      if(!$chachacha) {
      setcookie("user name");
      setcookie("uID" );
      return false;
      }else{
      $IPserver = $chachacha['IPaddress'];
      $diff = $chachacha['date']+constant("time Lim")-date("U");
      $IPrecent = $_SERVER["REMOTE_ADD R"];


      if(($IPserver != $IPrecent)||($d iff<0)){
      setcookie("user name");
      setcookie("uID" );
      return false;
      }else{
      $datu = date("U");
      mysql_query("UP DATE user SET date='$datu' WHERE username='$usi' ");
      return true;
      }
      }
      }else{
      setcookie("user name");
      setcookie("uID" );
      return false;

      }



      ?>
      [/code]

      you can use this function to check authorisation of user, and set his login validity period manualy, and it works better... i
      of course u need databe where you can store users password, uID (userid) and date (time of login). good luck.

      Comment

      Working...