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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:30:46+00:00 2026-06-06T06:30:46+00:00

Ok, i have one totaly noob question about php sessions: I have 3 (and

  • 0

Ok, i have one totaly noob question about php sessions:

I have 3 (and more) php pages, i need to protect them with login system and sessions. Now, i am including this to the top of every page:

session_name('somename');
session_start();

if(!$_SESSION['user_loggedIn']){
    header("location: login.php");
}

if (isset($_SESSION["timeout"])) {
$inactive = 900;
    $sessionTTL = time() - $_SESSION["timeout"];

      if ($sessionTTL > $inactive) {
        session_destroy();
        header("location: login.php");
      }

}

Question: is it correct to add something like include session.php; to top of every php file, ofc. session.php would include only code above.

  • 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-06T06:30:48+00:00Added an answer on June 6, 2026 at 6:30 am

    You shouldn’t need to handle the session timeout yourself, your webserver is almost certainly handling that for you already. All you should need to do is check to see if the session exists and make sure you have login info in that session.

    Also, as far as “what’s the right thing to do” — if you require it at the top of every php file, remember to use “require_once” because there’s no point in doing the same thing over and over if you include other files. Also, you may only need to do this on pages where you know you only want secured users, which isn’t always every page of the site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one XML request which I need to modify (to XML) and then
OK, total noob question, for msysgit on Windows 7, but I have a remote
i have one row of text boxes which is generated with php loop and
Total OO noob question here. I have these two methods in a class private
I've just begun diving into data warehousing and I have one question that I
Sorry about the really ambiguous question, I really have no idea how to word
I have one Class called System it contains some variables and two arrays and
I have one datatable. In that table I have columns named [Total Day], [Present
Ok, so i have one really monstrous MySQL table (900k records, 180 MB total),
I have a PopupMenu with submenus and only one item in total shall be

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.