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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:56:34+00:00 2026-05-11T03:56:34+00:00

I am creating a site and I’m using sessions to manage the user log

  • 0

I am creating a site and I’m using sessions to manage the user log in status. When a user logs in, I create a session id for the user like so:

$_SESSION['username'] = 'username'; 

How can I check if a user is logged in, and if so, who it is?

  • 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. 2026-05-11T03:56:35+00:00Added an answer on May 11, 2026 at 3:56 am

    If, after you have authenticated the user you are writing $_SESSION['username'] to the the session superglobal, all you need to do is double check the existance of a session username:

     session_start()  if (empty($_SESSION['username'])) {       // user is not logged in  } 

    Figuring out who is logged in is as simple as checking what username you have stored in the $_SESSION['username'] variable that we checked earlier. If you wanted to save their real name from a database result, or other information, just dump that information into the $_SESSION['data_type'] array as well.

    The session variables should automatically expire in 24 minutes (PHP default, I think) of inactivity, in which case you should expect the user to login again. If you want to log the user out immediately, check out session_destroy().

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

Sidebar

Related Questions

Creating a site in with FrogCMS and using alot of jquery to create an
I am progamatically creating a SharePoint site using SPWeb spWeb = spSite.AllWebs.Add(...); What code
I am currently creating an e-commerce site using C# ASP.NET MVC and have just
I creating a site in JRuby on Rails (JRuby 1.3.0 ). I am using
I'm creating web site on local computer. i'm using SQL Server 2005 management studio.
I'm creating a site that allows users to submit quotes. How would I go
I'm creating a multi-tenancy web site which hosts pages for clients. The first segment
When creating a web application, and lets say you have a User object denoting
I am creating site with php. On localhost all works well. On my hosting
I'm creating a site on which there are many page components that refer to

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.