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 7722347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:08:53+00:00 2026-06-01T04:08:53+00:00

I am using PHP to settle the session timeout…I found a few solutions so

  • 0

I am using PHP to settle the session timeout…I found a few solutions so i picked the one i understand the most which was:

    $now = time(); // checking the time now when home page starts

    if($now > $_SESSION['expire'])
    {
    session_destroy();
    echo "Your session has expire ! <a href='login.php'>Login Here</a>";
    };

I also added this in my login processor page

$_SESSION['start'] = time(); // taking now logged in time
$_SESSION['expire'] = $_SESSION['start'] + (30 * 60) ; // ending a session in 30 minutes from the starting time

from How do I expire a PHP session after 30 minutes?

The result was that the message Your session has expire ! <a href='login.php'>Login Here</a> did appear but the page was still in the homepage instead of going back to the login page…I was wondering if by adding header ('Location:login.php'); below the echo line will bring it back to the login page…

How do i change the echo message to pop up message instead together with bring the page back to login.php?

Thanks…I know there are answers online but I want to know where is my mistake so i can learn something here…Teaching and guidance is really appreciated

  • 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-01T04:08:54+00:00Added an answer on June 1, 2026 at 4:08 am

    You can not echo something and at the same time redirecting to the homepage with a header() call. The header call requires that you DON’T echo anything. Also, popups need you to use some sort of client-side scripting (ECMAScript/JavaScript). Try to output this code on logout instead of your message:

    <script>
    alert('Your session have expired! Please login again.');
    location.href = 'login.php';
    </script>
    

    Another solution is to NOT destroy the session entirely. Just unset all variables. Then store an error message in the session and redirect to the login page. Show the error message at the login page. Something like this:

    function my_session_destroy() {
      $_SESSION = array();
    }
    
    if (/* session expired  ...*/) {
      my_session_destroy();
      $_SESSION['error'] = 'Your session have expired. Please login and try again.';
      header('Location: login.php');
      exit(); //Always call exit() after a header('Location: ...') call!
    }
    

    At login.php:

    if(isset($_SESSION['error'])) {
      printf('<p class="error">%s</p>', $_SESSION['error']);
      unset($_SESSION['error']);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using php, i have a sql query which works fine, dateentry only has the
Help me settle an argument with a coworker... We’re using Zend Framework and PHP
Using PHP I am running str_replace many times in a row to switch one
using php, if possible. What does it mean? I was reading one of my
using PHP. It has to be a valid one, like: 2001-6-28 14:20:29 ? (and
Using PHP, if I set a custom session folder to store session files, what
Using PHP, I can convert MySQL data or static table data to csv, Excel,
Using PHP, I am trying to delete a record, but I want to check
using php and mysql I have two tables, a users table and a profiles
Using PHP and MySQL, I am integrating a site with a wiki based on

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.