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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:50:52+00:00 2026-06-13T23:50:52+00:00

I want to know in my application which is mainly php, which is best

  • 0

I want to know in my application which is mainly php, which is best method in order to keep a user logged into a site until they have logged off. Could it be tokens, sessionlife, cookies etc?

At the moment this is how my login and logoff system works:

When a user logs in, it stores in their details in a $_SESSION:

if (isset($_SESSION['teacherid'])) {

      $userid = $_SESSION['teacherid'];

  }

if (isset($_SESSION['teacherusername'])) {

      $username = $_SESSION['teacherusername'];

  }

Then in every script it contains the code below where the sessionlife lasts for 12 hours:

<?php

ini_set('session.gc_maxlifetime',12*60*60);
ini_set('session.gc_divisor', '1');
ini_set('session.gc_probability', '1');
ini_set('session.cookie_lifetime', '0');
require_once 'init.php'; 

session_start();

?>

init.php is this below:

 <?php
 session_save_path('Session'); 
 ?>

Now after 12 hours the next time the user refreshes the page, as the session will be destroyed, it goes to the logoff page:

    if ((isset($username)) && (isset($userid))){
        session_destroy();
        echo "You have been Logged Out | <a href='./home.php'>Home</a>";
    }

    else {

        echo "You are Not Logged In";

    }

Obviously if the user clicks on the logout page then it navigates to script above.

But is this a good way of doing it? Is there a much more convenient way because if you look at proper web applications, they can keep users logged in for days, but how do they do this?

Thanks

  • 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-13T23:50:54+00:00Added an answer on June 13, 2026 at 11:50 pm

    Sessions will do in a pinch, and they are secure enough (although don’t quote me on that), but depending on server usage and configuration, your sessions may be cleared before the 12-hour mark.

    Upon login, I initiate a session and save a cookie to their computer. This cookie contains a uniquely generated string and their account id.

    When they refresh the page, the following is run (pseudocode):

    if (session_exists) continue();
    else if (!session_exists AND cookie_exists AND validate_cookie()) {
        login_user_via_cookie();
        continue();
    else show_login_page();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to know that can i make an application which have some
I want to develop an application in which I need to know the position
I am developing an application which depends on libpcap and want to know how
I have an application which has a Prefernces Class and I want to know
I'm making an application which needs the user to log in. I want to
I want to let application user know that whom buddy has downloaded the application
I have one Application which has more then 5 Activity I want to know
I have a simple application which has an NSSearchField and I want to know
I have this rails Application which uses salesforce App. I want to know if
I have an application which uses Active Directory intensively. I want to know if

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.