CaptureIpTrait::getClientIp()   B
last analyzed

Complexity

Conditions 7
Paths 7

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 7
eloc 15
c 1
b 0
f 1
nc 7
nop 0
dl 0
loc 19
rs 8.8333
1
<?php
2
3
namespace App\Traits;
4
5
class CaptureIpTrait
6
{
7
    // private $ipAddress = null;
8
9
    public function getClientIp()
10
    {
11
        if (getenv('HTTP_CLIENT_IP')) {
12
            $ipAddress = getenv('HTTP_CLIENT_IP');
13
        } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
14
            $ipAddress = getenv('HTTP_X_FORWARDED_FOR');
15
        } elseif (getenv('HTTP_X_FORWARDED')) {
16
            $ipAddress = getenv('HTTP_X_FORWARDED');
17
        } elseif (getenv('HTTP_FORWARDED_FOR')) {
18
            $ipAddress = getenv('HTTP_FORWARDED_FOR');
19
        } elseif (getenv('HTTP_FORWARDED')) {
20
            $ipAddress = getenv('HTTP_FORWARDED');
21
        } elseif (getenv('REMOTE_ADDR')) {
22
            $ipAddress = getenv('REMOTE_ADDR');
23
        } else {
24
            $ipAddress = 'UNKNOWN';
25
        }
26
27
        return $ipAddress;
28
    }
29
}
30