add get ip&schema function

This commit is contained in:
xiaomlove
2022-04-07 00:54:05 +08:00
parent f2b9268a1f
commit e093b91133
8 changed files with 45 additions and 14 deletions
+1 -1
View File
@@ -128,7 +128,7 @@ class Install
public function listRequirementTableRows()
{
$gdInfo = function_exists('gd_info') ? gd_info() : [];
$extensions = ['ctype', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'bcmath', 'redis', 'gd', 'pcntl'];
$extensions = ['ctype', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml', 'mysqli', 'bcmath', 'redis', 'gd', 'pcntl', 'sockets'];
$tableRows = [];
$tableRows[] = [
'label' => 'PHP version',
+36
View File
@@ -92,6 +92,42 @@ final class Nexus
$this->logSequence++;
}
public function getRequestSchema()
{
$schema = $this->retrieveFromServer(['HTTP_X_FORWARDED_PROTO', 'REQUEST_SCHEME', 'HTTP_SCHEME']);
if (empty($schema)) {
$tmp = $this->retrieveFromServer(['HTTPS']);
if ($tmp == 'on') {
$schema = 'https';
}
}
return $schema;
}
public function getRequestIp()
{
$ip = $this->retrieveFromServer(['HTTP_CF_CONNECTING_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_REMOTE_ADDR']);
if (empty($ip)) {
$ip = request()->getClientIp();
}
return $ip;
}
private function retrieveFromServer(array $fields)
{
if ($this->runningInOctane()) {
$servers = request()->server();
} else {
$servers = $_SERVER;
}
foreach ($fields as $field) {
if (!empty($servers[$field])) {
do_log("got from $field");
return $servers[$field];
}
}
}
private function runningInOctane(): bool
{
if (defined('RUNNING_IN_OCTANE') && RUNNING_IN_OCTANE) {