-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpeicher.php
executable file
·81 lines (73 loc) · 1.48 KB
/
Speicher.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* @author Mesa <mesa@xebro.de>
* @license http://creativecommons.org/licenses/by-nc-sa/3.0/
* @link http://www.xebro.de
*
*/
/**
*
*/
class Speicher
{
protected $ip = array();
protected $regex = "/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/";
public function add ( $ip )
{
if ($this->isIp($ip)) {
if (isset($this->ip[$ip])) {
$this->ip[$ip]++;
} else {
$this->ip[$ip] = 1;
}
return true;
} else {
return false;
}
}
/**
* How many times was ip added
*
* @param [String] $ip Ip string
*
* @return [Int|Boolean] On Error false
*/
public function getCount ( $ip )
{
if ($this->isIp($ip)) {
if (isset($this->ip[$ip])) {
return $this->ip[$ip];
} else {
return 0;
}
} else {
return false;
}
}
/**
* Check for valid ip
*
* @param [String] $ip Ip
*
* @return [Boolean] valid === true
*/
protected function isIp ( $ip )
{
$match_count = preg_match($this->regex, $ip);
if ($match_count == 0) {
return false;
} else {
return true;
}
}
/**
* Get all added Ips
*
* @return [Array] All added Ips
*/
public function getAll ()
{
ksort($this->ip);
return $this->ip;
}
}