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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:39:00+00:00 2026-05-31T16:39:00+00:00

this seems like a simple enough question but I can’t seem to find a

  • 0

this seems like a simple enough question but I can’t seem to find a clear answer anywhere.

I am writing an app that will be used by multiple companies with multiple users. Each company, and it’s users only have access to it’s data. I want each company to have their own subdomain: i.e. company1.myapp.com, company2.myapp.com etc

When they enter that URL, i’m using the subdomain to get user info from the DB, from there they can log in. I’m setting their company ID (subdomain) as a session variable so the app knows what data it should be pulling from the DB

What I can’t work out:
– How do I lock authentication to the one subdomain? i.e. once authenticated, if i change the domain from company1.myapp.com to company2.myapp.com how can I ensure that the system knows the user is only authenticated to company1?

Any pointers appreciated.

Thanks,
Greg

  • 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-31T16:39:01+00:00Added an answer on May 31, 2026 at 4:39 pm

    Thanks to some help over at the Symfony forums I seem to have this working using a listener.

    define the listener #config.yml — take note of the priority, otherwise the page seems to render before killing the session.

    services:        
      company_listener:
        class: myApp\SecurityBundle\Controller\CompanyListener
        arguments: 
            security: "@security.context", 
            container: "@service_container"
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 64 }
    

    Listener class

    class CompanyListener extends controller
    {
    
    public static $companyID;
    private $securityContext;
    protected $container;
    
    public function __construct(SecurityContext $context, $container)
    {
        $this->securityContext = $context;
        $this->container = $container;
    }
    
    public function onKernelRequest(GetResponseEvent $event)
    {       
    
        $request = $event->getRequest();
        $session = $request->getSession();              
    
        $currentHost = $request->getHost();
    
        if(is_object($session)){
            $companyID = $session->get('companyID');
            $sessionHost = $session->get('subdomain');
    
            if ($sessionHost != $currentHost) {
                $this->get('request')->getSession()->invalidate();
            }           
        }
    
        $session->set('company', $currentHost);
    
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like a simple enough question but I can't seem to find the answer.
This seems like a simple question, but I can't find it with the Stack
This seems like a simple question, but it is difficult to search for. I
This seems like it would be fairly simple, but I've been unable to find
This sure seems like a simple error to fix. However, I somehow can't figure
This seems like it should be really simple, but I'm unable to figure this
Seems like this should be simple, but powershell is winning another battle with me.
This feels like it should be pretty simple, but not much seems to be
I hope I can make this question clear enough. I'm looking to put a
This seems like such a trivial question to ask, but it's been vexing me

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.