Welcome Guest, Not a member yet? Register   Sign In
muti domain support.
#4

here is the code for people interested in multi url support:
PHP Code:
app\Common.php
function detectBaseURL() : string
{
  // cache url
  static $finalURL null;
  if ($finalURL !== null) {
     return $finalURL;
  }
  $URLs config(App::class)->baseURL;
  // multi url support
  if (is_array($URLs))
  {
     $host = [$_SERVER['SERVER_NAME'], $_SERVER['SERVER_ADDR']];
     foreach ($URLs as $url
     {
        $schemaLength strpos($url'//') + 2;
        $hostLength  strpos($url'/'$schemaLength);
        $Host        substr($url$schemaLength$hostLength $schemaLength);
        if (in_array($Host$host))
        {
           $finalURL $url;
           break;
        }
     }
     // use first as backup
     if ($finalURL === null)
     {
        $finalURL $URLs[0];
     }
  } elseif (! is_string($URLs))
  {
     // TODO : handle invalid baseurl
     $finalURL = (string) $URLs;
  } else {
     $finalURL $URLs;
  }
  return $finalURL;

call
PHP Code:
detectBaseURL 
in app\Config\App.php constructor
PHP Code:
public function __construct()
{
   parent::__construct();
   $this->baseURL detectBaseURL();

if you want to separate the url strictly you could store a url id in the app config and check this in your controller ( or directly in your routes config )
Reply


Messages In This Thread
muti domain support. - by admin0 - 02-04-2019, 03:01 AM
RE: muti domain support. - by kilishan - 02-04-2019, 07:05 AM
RE: muti domain support. - by puschie - 02-11-2019, 06:06 AM
RE: muti domain support. - by puschie - 09-14-2021, 12:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB