Skip to content

Commit

Permalink
Merge pull request #160 from kivudesign/version_boss
Browse files Browse the repository at this point in the history
[UPD] remove serverdomain provider information from constant to the init file.
  • Loading branch information
bim-g authored Jan 5, 2024
2 parents 18b0186 + 3dc8fe2 commit 7658c43
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
37 changes: 0 additions & 37 deletions config/constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,43 +18,6 @@
*/
define('ROOT', str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']));

/**
* Get App domain
* define default domain
*/
/**
* Get host domain ip address
* @return string
*/
function getDomainIP(): string
{
$ip = $_SERVER['REMOTE_ADDR'];

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif ($ip == '::1') {
$ip = gethostbyname(getHostName());
}
return $ip;
}

/**
* Get server information's
* @return object
*/
function serverDomain(): object
{
$server_name = $_SERVER['SERVER_NAME'];
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? strtolower(explode('/', $_SERVER['SERVER_PROTOCOL'])[0]) : 'http';
$domain = getDomainIp() === '127.0.0.1' ? "$protocol://$server_name" : $server_name;
return (object)[
'server_name' => $server_name,
'protocol' => $protocol,
'domain' => $domain
];
}

/**
* Define default domain
Expand Down
41 changes: 41 additions & 0 deletions config/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,47 @@

session_start();

/**
* Get App domain
* define default domain
*/
/**
* Get host domain ip address
* @return string
*/
function getDomainIP(): string
{
$ip = $_SERVER['REMOTE_ADDR'];

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif ($ip == '::1') {
$ip = gethostbyname(getHostName());
}
return $ip;
}

/**
* Get server information's
* @return object
*/
function serverDomain(): object
{
$server_name = $_SERVER['SERVER_NAME'];
$protocol = isset($_SERVER['SERVER_PROTOCOL']) ? strtolower(explode('/', $_SERVER['SERVER_PROTOCOL'])[0]) : 'http';
$domain = getDomainIp() === '127.0.0.1' ? "$protocol://$server_name" : $server_name;
return (object)[
'server_name' => $server_name,
'protocol' => $protocol,
'domain' => $domain
];
}

/*
*
*/
require_once $ROOT_DIR . '/config/constant.php';
/**
* Application Global Configuration
Expand Down

0 comments on commit 7658c43

Please sign in to comment.