forked from samyk/evercookie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevercookie_etag.php
51 lines (45 loc) · 1.64 KB
/
evercookie_etag.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
<?php
/* evercookie, by samy kamkar, 09/20/2010
* http://samy.pl : code@samy.pl
*
* This is the server-side ETag software which tags a user by
* using the Etag HTTP header, as well as If-None-Match to check
* if the user has been tagged before.
*
* -samy kamkar
*/
// we don't have a cookie, so we're not setting it
if (!$_COOKIE["evercookie_etag"])
{
// read our etag and pass back
if (!function_exists('apache_request_headers')) {
function apache_request_headers() {
// Source: http://www.php.net/manual/en/function.apache-request-headers.php#70810
$arh = array();
$rx_http = '/\AHTTP_/';
foreach ($_SERVER as $key => $val) {
if (preg_match($rx_http, $key)) {
$arh_key = preg_replace($rx_http, '', $key);
$rx_matches = array();
// do some nasty string manipulations to restore the original letter case
// this should work in most cases
$rx_matches = explode('_', $arh_key);
if (count($rx_matches) > 0 and strlen($arh_key) > 2) {
foreach ($rx_matches as $ak_key => $ak_val)
$rx_matches[$ak_key] = ucfirst($ak_val);
$arh_key = implode('-', $rx_matches);
}
$arh[$arh_key] = $val;
}
}
return ($arh);
}
}
$headers = apache_request_headers();
echo $headers['If-None-Match'];
exit;
}
// set our etag
header('Etag: ' . $_COOKIE["evercookie_etag"]);
echo $_COOKIE["evercookie_etag"];
?>