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

  • Home
  • SEARCH
  • 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 8601649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:53:34+00:00 2026-06-12T01:53:34+00:00

When handling user authentication in PHP with sessions, I see two main options for

  • 0

When handling user authentication in PHP with sessions, I see two main options for accessing the user’s properties after successfully logging in:

  1. Load the user’s main properties into the session superglobal
  2. Load only the user’s UID (username or id # etc) into the session e.g. $_SESSION['username'], then fetch the user’s main properties on page load and store these in a user object

Method 1

  • Scope is more easily accessible through the session superglobal

Method 2

  • You don’t have to worry about updating the session variables when the user’s data is modified, since you’re fetching it on each page

My questions

  • Am I overlooking other options?
  • What is generally the “done” way?
  • What about performance? Which method will be quicker under which circumstances?

Notes

  • When I say the user’s “main” properties, I refer to those which will be used on many pages, such as the user’s name, access level, email address etc. Obviously you wouldn’t load too large an amount of data.

  • I am referring to database-stored sessions and not file-based.

  • 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-12T01:53:35+00:00Added an answer on June 12, 2026 at 1:53 am

    Usually, only the UID or any other unique identifier (e.g. the username) is stored because all other data could be changed dynamically.
    However, it depends on the data and the project itself. Loading e.g. access level, username and email as you said in addition to the UID could be highly efficient if those data is used often and you really care about updating them!
    On the other hand, only storing the UID is inefficient because you have to request all data on each page but it’s a more secure approach. Anyway, if you need to load further user data on most pages, this approach would be the better one because you have to request data anyway.
    Nevertheless, to increase the efficiency of e.g. database request you could use a database cache. If you do so, the efficiency of both ways may be nearly equal.
    In short, it really depends on the type of project, needed data and environment which approach is the better and more efficient one.

    Please be also aware that if you store user data other than the UID you need to save session IDs too because a user could open more than one session and you need to make sure that he changes the same session if he changes user data!

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

Sidebar

Related Questions

I use authlogic for authentication and paperclip for handling user's profile picture attachments. I
Should I write authentication logic in my forms for handling user login? For example,
I've (so far) been handling user sessions with client-side cookies and database entries. When
Just wondering what the best practice for handling login/user authentication in mvc3 would be.
I'm interested in what strategies can be used for handling user authentication and authorization
Hy guys, I decided to use FOSUserBundle for handling user authentication in my application.
I have two user models one is 1. User.rb (this is my own authentication
The standard tutorials for J2EE 6 show the handling of user authentication as follows:
I am new to Windows forms and having an issue handling all the user
I was handling yet another KeyDown event in a user control when I wondered

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.