Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use empty everywhere and standartize whitespaces/braces
  • Loading branch information
garex committed Oct 15, 2014
1 parent 86eec22 commit b695fa0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
9 changes: 4 additions & 5 deletions php/evercookie_cache.php
Expand Up @@ -8,15 +8,14 @@
*/

// we don't have a cookie, user probably deleted it, force cache
if (!$_COOKIE["evercookie_cache"])
{
header("HTTP/1.1 304 Not Modified");
exit;
if (empty($_COOKIE['evercookie_cache'])) {
header('HTTP/1.1 304 Not Modified');
exit;
}

header('Content-Type: text/html');
header('Last-Modified: Wed, 30 Jun 2010 21:36:48 GMT');
header('Expires: Tue, 31 Dec 2030 23:30:45 GMT');
header('Cache-Control: private, max-age=630720000');

echo $_COOKIE["evercookie_cache"];
echo $_COOKIE['evercookie_cache'];
9 changes: 3 additions & 6 deletions php/evercookie_etag.php
Expand Up @@ -10,12 +10,10 @@
*/

// we don't have a cookie, so we're not setting it
if (!isset($_COOKIE['evercookie_etag']) || empty($_COOKIE['evercookie_etag'])) {
if (empty($_COOKIE['evercookie_etag'])) {
// read our etag and pass back
if (!function_exists('apache_request_headers')) {

function 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_/';
Expand All @@ -35,14 +33,13 @@ function apache_request_headers()
$arh[$arh_key] = $val;
}
}

return ($arh);
}
}

$headers = apache_request_headers();
if(isset($headers['If-None-Match'])) {
header('Etag: '.$headers['If-None-Match']);
header('Etag: ' . $headers['If-None-Match']);
echo $headers['If-None-Match'];
}
exit;
Expand Down
37 changes: 18 additions & 19 deletions php/evercookie_png.php
Expand Up @@ -9,7 +9,7 @@
*
* If for any reason this file is accessed again WITHOUT the cookie,
* as in the user deleted their cookie, the code returns back with
* a forced "Not Modified" meaning the browser should look at its
* a forced 'Not Modified' meaning the browser should look at its
* cache for the image.
*
* The client-side code then places the cached image in a canvas and
Expand All @@ -19,10 +19,11 @@
*/

// we don't have a cookie, user probably deleted it, force cache
if (!isset($_COOKIE["evercookie_png"]))
{
if(!headers_sent()) header("HTTP/1.1 304 Not Modified");
exit;
if (empty($_COOKIE['evercookie_png'])) {
if(!headers_sent()) {
header('HTTP/1.1 304 Not Modified');
}
exit;
}

// width of 200 means 600 bytes (3 RGB bytes per pixel)
Expand All @@ -31,26 +32,24 @@

$gd = imagecreatetruecolor($x, $y);

$data_arr = str_split($_COOKIE["evercookie_png"]);
$data_arr = str_split($_COOKIE['evercookie_png']);

$x = 0;
$y = 0;
for ($i = 0, $i_count = count($data_arr); $i < $i_count; $i += 3)
{
$red = isset($data_arr[$i]) ? ord($data_arr[$i]) : 0;
$green = isset($data_arr[$i+1]) ? ord($data_arr[$i+1]) : 0;
$blue = isset($data_arr[$i+2]) ? ord($data_arr[$i+2]) : 0;
$color = imagecolorallocate($gd, $red, $green, $blue);
imagesetpixel($gd, $x++, $y, $color);
for ($i = 0, $i_count = count($data_arr); $i < $i_count; $i += 3) {
$red = isset($data_arr[$i]) ? ord($data_arr[$i]) : 0;
$green = isset($data_arr[$i+1]) ? ord($data_arr[$i+1]) : 0;
$blue = isset($data_arr[$i+2]) ? ord($data_arr[$i+2]) : 0;
$color = imagecolorallocate($gd, $red, $green, $blue);
imagesetpixel($gd, $x++, $y, $color);
}

if(!headers_sent()){
header('Content-Type: image/png');
header('Last-Modified: Wed, 30 Jun 2010 21:36:48 GMT');
header('Expires: Tue, 31 Dec 2030 23:30:45 GMT');
header('Cache-Control: private, max-age=630720000');
if(!headers_sent()) {
header('Content-Type: image/png');
header('Last-Modified: Wed, 30 Jun 2010 21:36:48 GMT');
header('Expires: Tue, 31 Dec 2030 23:30:45 GMT');
header('Cache-Control: private, max-age=630720000');
}

// boom. headshot.
imagepng($gd);

0 comments on commit b695fa0

Please sign in to comment.