mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
add get ip&schema function
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user