first commit
This commit is contained in:
46
app/Helpers/Global/geo_helper.php
Normal file
46
app/Helpers/Global/geo_helper.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
if (! function_exists('get_current_ip')) {
|
||||
function get_current_ip()
|
||||
{
|
||||
$ip = null;
|
||||
|
||||
if (app()->environment() == 'local') {
|
||||
return config('platform.general.dev_default_ip');
|
||||
}
|
||||
|
||||
if (getenv('HTTP_CF_CONNECTING_IP')) {
|
||||
$ip = getenv('HTTP_CF_CONNECTING_IP');
|
||||
} elseif (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
|
||||
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
|
||||
}
|
||||
|
||||
if (! is_empty($ip)) {
|
||||
return $ip;
|
||||
}
|
||||
|
||||
$ip_add_set = null;
|
||||
|
||||
if (getenv('HTTP_CLIENT_IP')) {
|
||||
$ip_add_set = getenv('HTTP_CLIENT_IP');
|
||||
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
|
||||
$ip_add_set = getenv('HTTP_X_FORWARDED_FOR');
|
||||
} elseif (getenv('HTTP_X_FORWARDED')) {
|
||||
$ip_add_set = getenv('HTTP_X_FORWARDED');
|
||||
} elseif (getenv('HTTP_FORWARDED_FOR')) {
|
||||
$ip_add_set = getenv('HTTP_FORWARDED_FOR');
|
||||
} elseif (getenv('HTTP_FORWARDED')) {
|
||||
$ip_add_set = getenv('HTTP_FORWARDED');
|
||||
} elseif (getenv('REMOTE_ADDR')) {
|
||||
$ip_add_set = getenv('REMOTE_ADDR');
|
||||
} elseif (isset($_SERVER['REMOTE_ADDR'])) {
|
||||
$ip_add_set = $_SERVER['REMOTE_ADDR'];
|
||||
} else {
|
||||
$ip_add_set = '127.0.0.0';
|
||||
}
|
||||
|
||||
$ip_add_set = explode(',', $ip_add_set);
|
||||
|
||||
return $ip_add_set[0];
|
||||
}
|
||||
}
|
||||
5
app/Helpers/Global/helpers.php
Normal file
5
app/Helpers/Global/helpers.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
require 'string_helper.php';
|
||||
require 'geo_helper.php';
|
||||
38
app/Helpers/Global/string_helper.php
Normal file
38
app/Helpers/Global/string_helper.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
if (! function_exists('is_empty')) {
|
||||
/**
|
||||
* A better function to check if a value is empty or null. Strings, arrays, and Objects are supported.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
function is_empty($value): bool
|
||||
{
|
||||
if (is_null($value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (is_string($value)) {
|
||||
if ($value === '') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
if (count($value) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
$value = (array) $value;
|
||||
|
||||
if (count($value) === 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user