Jump to content

Recommended Posts

As my title said the question, i want to destroy my session after a particular time if user is being ideal..

currently i am using this code to define my session:

 


session_start();
// Check, if username session is NOT set then this page will jump to login page
if (!isset($_SESSION['myusername'])) {
header('Location: admin.php');
}

 

<?php
    session_start();
     
    // timeout after 10 minutes
    $inactive = 600;
     
    $session_life = time() - $_session['timeout'];
     
    if($session_life > $inactive)
    { session_destroy(); header("Location: logoutpage.php"); }
    S_session['timeout']=time();
?>

You need to be more specific, do you want:

1)  The session to expire after a certain amount of inactivity?  For instance, if they get up and go to lunch, when they come back they'll be logged out?

2)  The session to expire at a specific time after login regardless of their activity.  For instance, they can only browse your site for 4 hours before they're automatically kicked out?

You need to be more specific, do you want:

1)  The session to expire after a certain amount of inactivity?  For instance, if they get up and go to lunch, when they come back they'll be logged out?

2)  The session to expire at a specific time after login regardless of their activity.  For instance, they can only browse your site for 4 hours before they're automatically kicked out?

 

I need something like "The session to expire after a certain amount of inactivity?  For instance, if they get up and go to lunch, when they come back they'll be logged out?"...

 

session_set_cookie_params allows you to set the timeout for the user's session cookie.

 

kney's solution accomplishes roughly the same thing at the server level, but note that you need to die() after a header() call.

session_set_cookie_params allows you to set the timeout for the user's session cookie.

 

kney's solution accomplishes roughly the same thing at the server level, but note that you need to die() after a header() call.

 

Thanks for a very quick reply but can you give me some coding, actually i am very new in PHP... A example code would be a grate help..

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.