From 3dc8fe2b68a2ccaad45bdbe9ee8603ac1958ba78 Mon Sep 17 00:00:00 2001 From: bim-g Date: Fri, 5 Jan 2024 13:32:09 +0200 Subject: [PATCH] [UPD] remove serverdomain provider information from constant to the init file. --- config/constant.php | 37 ------------------------------------- config/init.php | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/config/constant.php b/config/constant.php index 1a5d42c..71abd7d 100644 --- a/config/constant.php +++ b/config/constant.php @@ -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 diff --git a/config/init.php b/config/init.php index 2d5e1dc..1f1c73f 100644 --- a/config/init.php +++ b/config/init.php @@ -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