Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9141681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:40:39+00:00 2026-06-17T09:40:39+00:00

When users login their online status is set to 1 when they logout its

  • 0

When users login their online status is set to 1 when they logout its set back to 0, im trying to make it so after a certain amount of time of inactivity on the site they will be sent to logout.php, so I setup a field in my users table as last_activity as a timestamp. and have this code as a include on each page.

<?php
if (!isset($_SESSION['last_activity'])) {
    // initiate value
    $_SESSION['last_activity'] = time();
}
if (time() - $_SESSION['last_activity'] > 500) {
    // last activity is longer then certain amount of time
    header('Location: logout.php');
} else {
    // update last activity timestamp
    $_SESSION['last_activity'] = time();
}
?>

But right now as I have it, the last_activity field only updates when something on the users account is updated, also after the certain amount of time the user isn’t logged out and I don’t know why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:40:40+00:00Added an answer on June 17, 2026 at 9:40 am

    From automatic logout after 15 minutes of inactivity:

    <?php
    session_start();
    $timeout = 10; // Set timeout minutes
    $logout_redirect_url = "index.php"; // Set logout URL
    
    $timeout = $timeout * 60; // Converts minutes to seconds
    if (isset($_SESSION['start_time'])) {
        $elapsed_time = time() - $_SESSION['start_time'];
        if ($elapsed_time >= $timeout) {
            session_destroy();
            header("Location: $logout_redirect_url");
        }
    }
    $_SESSION['start_time'] = time();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying make a login window where a user is prompted to enter their
Ok so here is my issue, Some users cannot login to their accounts. They
I have website where users can login with their Facebook account. I am using
Users can use their Google, Facebook or Twitter account to login to a site
Upon user login I check their roles. If they have no roles I want
What we need: redirect to each user's specific page after their login. What we
I am developing a iOS application which allows users to login by using their
I want to create a online diary kind of website were users can login
I have a simple chat client set up that allows users to login with
I am building a PHP site where the users login with their Linkedin account

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.