php - Destroy a session and automatically loads the page -


i want destroy session after 3 minutes i'm doing that, problem when reloads page take me previous page want automatically reloads previous page after 3 minutes(i.e when session destroyed)

php:

session_start();              if($_request['btn_logout'])             {                    $_session['time']=time()+180;                 $_session['name']="";                 header("location:login.php?msg=logout successfully");             }                                            if ($_session['time']&&time()-$_session['time']>180)             {                                                    $d=$_session['data'];                 $email=$_session['email'];                 $count=0;                 for($i=0 ;$i<count($email);$i++)                 {                                                            foreach($d $key)                     {                                                                    $count++;                         if($_request['name']==$key['user_email'] && $_request['pass']==$key['user_password'])                         {                                                                            if(count($email)==1)                             {                                                                                    session_unset();                                 session_destroy();                                 header("location:login.php?msg=your session got expired");                             }                             else                             {                                                                                $arr=array_keys($_session['data']);                                                                                  unset($_session['data'][$arr[$count-1]]);                                 unset($_session['email'][$arr[$count-1]]);                             }                                                                                                                     }                                                            }                                                    }                         }        

you leverage unofficial supported refresh header:

header('refresh: 180; url=login.php'); //               ^^^ 3 minutes in seconds. 

however, make more sense have client handle javascript. weak solution literally waiting 3 seconds , redirecting polling server every 10-15 seconds check if session has expired.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -