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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:06:30+00:00 2026-06-13T07:06:30+00:00

After the user has logged in I want to be able to save the

  • 0

After the user has logged in I want to be able to save the userId for later use within the application. The only place in the application I retrieve the username is from the login form, through the login controller. However, that structure in my application is that the only thing that is passed to my master controller from the login controller is HTML.

Of course I could include the userId in a hidden field inside the HTML that’s passed back to the master controller, but that seems too hacky.

So, is there a way that I can save a value (in this case the username) so that it’s accessible from other classes/namespaces/functions whatever? I have read a bit about ‘global’, but haven’t managed to get it work in my application.

from LoginController.php:

if ($loginView->TriedToLogin()){
    $loginUsername = $loginView->GetUserName();   //Retrieved from form
    $loginPassword = $loginView->GetPassword();
}
  • 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-13T07:06:31+00:00Added an answer on June 13, 2026 at 7:06 am

    Upon login, you need to store your user token in a session.

    See: https://www.php.net/manual/en/features.sessions.php

    Store user when logging in:

    $_SESSION['user_id'] = 32; // fetch from your user provider
    

    You can then write a class/function that utilises the session to check their login status and fetch their details when required.

    Like so:

    function getUserId()
    {
        return isset($_SESSION['user_id']) ? $_SESSION['user_id'] : false;
    }
    
    function isLoggedIn()
    {
        return isset($_SESSION['user_id']) && is_numeric($_SESSION['user_id']);
    }
    

    Then use anywhere in your application:

    echo isLoggedIn() ? getUserId() : 'Anonymous';
    

    Also, for great information on how to build an MVC framework, check out "Create your own framework… on top of the Symfony2 Components".

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

Sidebar

Related Questions

I need to do some processing only after the user has successfully logged in
After the user has logged in I want to make a redirect if /login
I want to INSERT VALUES after user has clicked OK on the confirmation box.
i want to clear the fields of my form after the user has inserted
Before the user has logged in with Facebook the app looks like After the
In a registration procedure, after a user has successfully registered, I need to output
My app has a session timeout after 30 minutes. If the user has a
After a user submits a form, how do you detect that the form has
Is there a way to allow a user, after he has created a vector
Here I am explaining the scenario - The user, after providing a service has

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.