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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:06:12+00:00 2026-05-27T03:06:12+00:00

I have persistent login in my website so if user checks the remember me

  • 0

I have persistent login in my website so if user checks the “remember me” while login process, set cookies to keep user alive all the times in that browser..

There are two routes to access to any page.. If it’s not ajax request, requests go through index.php but if request is ajax it’s just go through ajax.php.

To handle user request first I check session that whether userid stored or not, if session holds user there is no problem, request will be completed.
But if there is no current user id in session, I checked to cookie for autologin, if i can login user through cookie, force to login automatically with cookie data, and set Session with userid while user doesnt do anything..

Right now to handle it, I do the same process at the top of index.php and ajax.php like this;

class SessionManager
{
    private function __construct()
    { ; }

    public static function getSessionUser()
    {
        $user = NULL;

        if(isset($_SESSION['user']))
            $user   = $_SESSION['user'];
        else
        {


 /* Get username from cookie, and login it and set Session with user if it's possible otherwise do nothing Session is empty */
            getUserFromCookie();
            if(isset($_SESSION['user']))
                $user   = $_SESSION['user'];
        }

        return $user;
    }
}

In index.php;

$user = SessionManager::getSessionUser();

if(!isset($user))
{
   include dirname(__FILE__)."/controllers/login_controller.php";
}

and in ajax.php;

$user = SessionManager::getSessionUser();

if(!isset($user))
{
   echo json_encode(array("error" => true, "type" => NOT_ALLOWED, "message" => "User should login"));
}

So it works in all cases (I guess :)) , but what I wondering is what’s the best practice to handle it? Any other ideas?

  • 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-05-27T03:06:13+00:00Added an answer on May 27, 2026 at 3:06 am

    Here is one example of how to create persistent login with PHP, where the database is used in combination with a cookie, to verify that the cookie is authentic:

    http://jeremycook.ca/2010/03/28/creating-a-persistent-login-mechanism/

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

Sidebar

Related Questions

Why do i have to use some persistent-login module to make my users login
I have a login problem. First i am using SSL while logging. When i
I want to save user's authentication information in browser cookie for persistent login. As
I have an MVC 2.0 application that requires a persistent login(if chosen) using forms
I have persistent object, with a string property that often is over 500 charachters.
I have a persistent class Author with two fields: int id , String name
As far as I know, memcached runs in-memory and does not have a persistent
I am using the SQLite database and have the following persistent class (simplified): public
I have an application which stores data to the persistent store by setting the
In my previous understanding, for a web site, only login user of a web

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.