Server::IP()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace NirjharLo\Cgss\Lib\Analysis\Lib;
3
4
if ( ! defined( 'ABSPATH' ) ) exit;
5
6
7
/**
8
 * Get server features from header, taken from the url.
9
 *
10
 * 2 properties:
11
 * @property array $header Input header, whose social value is to be counted
12
 * @property string $domain Domain name
13
 */
14
class Server {
15
16
17
	public $header;
18
	public $domain;
19
20
	//check cache
21
	public function cache() {
22
23
		$cache = 0;
24
		if ( is_array( $this->header ) ) {
0 ignored issues
show
introduced by
The condition is_array($this->header) is always true.
Loading history...
25
			if ( array_key_exists( "Cache-Control", $this->header ) ) {
26
				$cache_val = $this->header["Cache-Control"];
27
				if ( $cache_val ) {
28
					$cache = 1;
29
				}
30
			}
31
		}
32
		return $cache;
33
	}
34
35
36
	//check if modified since
37
	public function if_mod() {
38
39
		$if_mod = 0;
40
		if ( is_array( $this->header ) ) {
0 ignored issues
show
introduced by
The condition is_array($this->header) is always true.
Loading history...
41
			if ( array_key_exists( "Last-Modified", $this->header ) ) {
42
				$if_mod = 1;
43
			}
44
		}
45
		return $if_mod;
46
	}
47
48
49
	//check keep alive
50
	public function alive() {
51
52
		$alive = 0;
53
		if ( is_array( $this->header ) ) {
0 ignored issues
show
introduced by
The condition is_array($this->header) is always true.
Loading history...
54
			if ( array_key_exists( "Connection", $this->header ) ) {
55
				$connection = $this->header["Connection"];
56
				if ( $connection == "Keep-Alive" ) {
57
					$alive = 1;
58
				}
59
			}
60
		}
61
		return $alive;
62
	}
63
64
65
	//check gZip compression
66
	public function gzip() {
67
68
		$gzip = 0;
69
		$encode = $_SERVER['HTTP_ACCEPT_ENCODING'];
70
		if ( substr( $encode, 0, 4 ) == 'gzip' ) {
71
			$gzip = 1;
72
		}
73
		return $gzip;
74
	}
75
76
77
	//Get the IP address
78
	public function IP() {
79
80
		$IP = gethostbyname( $this->domain );
81
		return $IP;
82
	}
83
}
84
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
85