Skip to content

Commit 0671a4e

Browse files
committed
moved
1 parent f8c64f0 commit 0671a4e

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed
File renamed without changes.
File renamed without changes.

php/evercookie_cache.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/* evercookie, by samy kamkar, 09/20/2010
3+
* http://samy.pl : [email protected]
4+
*
5+
* This is the server-side simple caching mechanism.
6+
*
7+
* -samy kamkar
8+
*/
9+
10+
// we don't have a cookie, user probably deleted it, force cache
11+
if (!$_COOKIE["evercookie_cache"])
12+
{
13+
header("HTTP/1.1 304 Not Modified");
14+
exit;
15+
}
16+
17+
header('Content-Type: text/html');
18+
header('Last-Modified: Wed, 30 Jun 2010 21:36:48 GMT');
19+
header('Expires: Tue, 31 Dec 2030 23:30:45 GMT');
20+
header('Cache-Control: private, max-age=630720000');
21+
22+
echo $_COOKIE["evercookie_cache"];
23+
24+
?>

php/evercookie_etag.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/* evercookie, by samy kamkar, 09/20/2010
3+
* http://samy.pl : [email protected]
4+
*
5+
* This is the server-side ETag software which tags a user by
6+
* using the Etag HTTP header, as well as If-None-Match to check
7+
* if the user has been tagged before.
8+
*
9+
* -samy kamkar
10+
*/
11+
12+
// we don't have a cookie, so we're not setting it
13+
if (!isset($_COOKIE['evercookie_etag']) || empty($_COOKIE['evercookie_etag'])) {
14+
// read our etag and pass back
15+
if (!function_exists('apache_request_headers')) {
16+
17+
function apache_request_headers()
18+
{
19+
// Source: http://www.php.net/manual/en/function.apache-request-headers.php#70810
20+
$arh = array();
21+
$rx_http = '/\AHTTP_/';
22+
foreach ($_SERVER as $key => $val) {
23+
if (preg_match($rx_http, $key)) {
24+
$arh_key = preg_replace($rx_http, '', $key);
25+
$rx_matches = array();
26+
// do some nasty string manipulations to restore the original letter case
27+
// this should work in most cases
28+
$rx_matches = explode('_', $arh_key);
29+
if (count($rx_matches) > 0 and strlen($arh_key) > 2) {
30+
foreach ($rx_matches as $ak_key => $ak_val) {
31+
$rx_matches[$ak_key] = ucfirst($ak_val);
32+
}
33+
$arh_key = implode('-', $rx_matches);
34+
}
35+
$arh[$arh_key] = $val;
36+
}
37+
}
38+
39+
return ($arh);
40+
}
41+
}
42+
43+
$headers = apache_request_headers();
44+
echo $headers['If-None-Match'];
45+
46+
header('Etag: $headers["If-None-Match"]')
47+
exit;
48+
}
49+
50+
// set our etag
51+
header('Etag: ' . $_COOKIE['evercookie_etag']);
52+
echo $_COOKIE['evercookie_etag'];

php/evercookie_png.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/* evercookie, by samy kamkar, 09/20/2010
3+
* http://samy.pl : [email protected]
4+
*
5+
* This is the server-side variable PNG generator for evercookie.
6+
* If an HTTP cookie is passed, the cookie data gets converted into
7+
* RGB-values in a PNG image. The PNG image is printed out with a
8+
* 20-year cache expiration date.
9+
*
10+
* If for any reason this file is accessed again WITHOUT the cookie,
11+
* as in the user deleted their cookie, the code returns back with
12+
* a forced "Not Modified" meaning the browser should look at its
13+
* cache for the image.
14+
*
15+
* The client-side code then places the cached image in a canvas and
16+
* reads it in pixel by pixel, converting the PNG back into a cookie.
17+
*
18+
* -samy kamkar
19+
*/
20+
21+
// we don't have a cookie, user probably deleted it, force cache
22+
if (!$_COOKIE["evercookie_png"])
23+
{
24+
header("HTTP/1.1 304 Not Modified");
25+
exit;
26+
}
27+
28+
// width of 200 means 600 bytes (3 RGB bytes per pixel)
29+
$x = 200;
30+
$y = 1;
31+
32+
$gd = imagecreatetruecolor($x, $y);
33+
34+
$data_arr = str_split($_COOKIE["evercookie_png"]);
35+
36+
$x = 0;
37+
$y = 0;
38+
for ($i = 0; $i < count($data_arr); $i += 3)
39+
{
40+
$color = imagecolorallocate($gd, ord($data_arr[$i]), ord($data_arr[$i+1]), ord($data_arr[$i+2]));
41+
imagesetpixel($gd, $x++, $y, $color);
42+
}
43+
44+
header('Content-Type: image/png');
45+
header('Last-Modified: Wed, 30 Jun 2010 21:36:48 GMT');
46+
header('Expires: Tue, 31 Dec 2030 23:30:45 GMT');
47+
header('Cache-Control: private, max-age=630720000');
48+
49+
// boom. headshot.
50+
imagepng($gd);
51+
52+
?>

0 commit comments

Comments
 (0)