Welcome Guest, Not a member yet? Register   Sign In
Multile domain pointed to a signle application
#1
Sad 

I have an application with 3 modules as follows-
  • Admin
  • Provider
  • Client
now I have a requirement that two different domains will hit the same site and the conditions I have to apply on this are given below 
from domain 1 user can access the client module only and from domain 2 user can access only Admin and Provider modules.

is there any way we can segregate and target modules as per domain?
Learning Codeigniter 
Reply
#2

(10-26-2022, 01:22 AM)SubrataJ Wrote: I have an application with 3 modules as follows-
  • Admin
  • Provider
  • Client
now I have a requirement that two different domains will hit the same site and the conditions I have to apply on this are given below 
from domain 1 user can access the client module only and from domain 2 user can access only Admin and Provider modules.

is there any way we can segregate and target modules as per domain?

This is what I have done so far and working.

Inside app/Config/Constants.php

PHP Code:
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' 'https://' $_SERVER['HTTP_HOST'] . '/' 'http://' $_SERVER['HTTP_HOST'] . '/';
defined('DOMAIN')                  || define('DOMAIN'preg_replace("/^[\w]{2,6}:\/\/([\w\d\.\-]+).*$/""$1"$protocol)); 



and then created a filter

PHP Code:
    public function before(RequestInterface $request$arguments null)
    {
        if (DOMAIN != 'domainName.com')
            throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
    

after that I have applied it inside routes.php

PHP Code:
$routes->group('client', ['namespace' => 'ClientDashboard\Controllers''filter' => 'client-domain'], function ($routes) {
    $routes->get('client/dashboard''DashboardController');
}); 


to be honest, I have no idea if this is the convenient way to do this or not, but for now, it's working as I wanted.
Learning Codeigniter 
Reply
#3

Validate the $_SERVER['HTTP_HOST'].
Otherwise you'll make vulnerability.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB