1 | <?php |
||
27 | class Fingerprint implements FingerprintInterface |
||
28 | { |
||
29 | /** |
||
30 | * The current request's client IP |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $clientFingerprint = array(); |
||
35 | |||
36 | /** |
||
37 | * grab things from the http request we need to use. |
||
38 | * |
||
39 | * @return string[] array of fingerprint values |
||
40 | */ |
||
41 | protected function takePrint() |
||
42 | { |
||
43 | $clientFingerprint = array(); |
||
44 | $httpRequest = HttpRequest::getInstance(); |
||
45 | $clientFingerprint['clientIp'] = $httpRequest->getClientIp(); |
||
46 | $clientFingerprint['userAgent'] = $this->makeInert($httpRequest->getHeader('USER_AGENT')); |
||
47 | $clientFingerprint['acceptLanguage'] = $this->makeInert($httpRequest->getHeader('ACCEPT_LANGUAGE')); |
||
48 | |||
49 | return $clientFingerprint; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Neutralize some sequences that might be used to slip nefarious bits into our fingerprint. |
||
54 | * This does not impair the similarity check, but does interfere with serialized object injection. |
||
55 | * |
||
56 | * @param string $value fingerprint string to be escaped |
||
57 | * |
||
58 | * @return string |
||
59 | */ |
||
60 | protected function makeInert($value) |
||
64 | |||
65 | /** |
||
66 | * This method manages the session fingerprint |
||
67 | * |
||
68 | * Check current client Fingerprint against the values saved in the session. |
||
69 | * Save the current Fingerprint to the session |
||
70 | * Rate the fingerprint match pass/fail based on any changes |
||
71 | * On fail, clear the session, leaving only the new client fingerprint |
||
72 | * |
||
73 | * @param AttributeInterface $session session manager object or another |
||
74 | * AttributeInterface implementing object |
||
75 | * |
||
76 | * @return bool true if matched, false if not |
||
77 | */ |
||
78 | public function checkSessionPrint(AttributeInterface $session) |
||
105 | } |
||
106 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: