Skip to content

Commit

Permalink
Remove awful big if else satement.
Browse files Browse the repository at this point in the history
  • Loading branch information
AsteroidusTv committed Aug 3, 2024
1 parent c51fb11 commit 0af52f1
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions api/utils/getClientIp.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php
function getClientIp() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
$headers = [
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'REMOTE_ADDR'
];

foreach ($headers as $header) {
if (isset($_SERVER[$header])) {
return $_SERVER[$header];
}
}

?>
return 'UNKNOWN';
}
?>

0 comments on commit 0af52f1

Please # to comment.