Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active August 29, 2015 14:08
Show Gist options
  • Save renoirb/db4b208b9a40a0c72ad5 to your computer and use it in GitHub Desktop.
Save renoirb/db4b208b9a40a0c72ad5 to your computer and use it in GitHub Desktop.
Improving (a bit) web browsing anonymity

Description

To prevent web browsing tracking you can trick tracking scripts by serving our own files that does nothing.

Such setup is perfect in combination with browser utilities such as Ghostery that sits in the web browser and blocks known tracking servers.

An interesting article on the same topic can expand more on the subject.

Instructions

Add a few intries in your local computer hosts file. This file is used by the operating system to get to know which IP address to use for given names. The hosts file is common for most modern operating systems; Windows, Mac OS, Linux, etc.

Hosts file format

The number 127.0.0.1 is the IP address of your local computer. An entry looks like this

127.0.0.1 adadvisor.net

Get hosts entries

A few sites provide a list of hosts file, you can make

Add entries

To edit a system protected file, I suggest you take a look at the directives in the following articles

Enable MacOS X web server and PHP

To enable local web server, you can take a look at the following articles

You can add the following lines in /private/etc/apache2/other/php5.conf. If the file doesn’t exist, you can create it.

ServerTokens Prod

<VirtualHost _default_:80>
  ServerName    localhost

  DocumentRoot  "/Library/WebServer/Documents"

  ErrorLog      "/private/var/log/apache2/hosts-error_log"
  CustomLog     "/private/var/log/apache2/hosts-access_log" common

  LoadModule php5_module libexec/apache2/libphp5.so
  AddType application/x-httpd-php .php

  <Directory "/Library/WebServer/Documents">
    DirectoryIndex index.php
    ErrorDocument 404 /index.php
    ErrorDocument 403 /index.php
    Options FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
<?php
/**
* Overriden localhost
*
* Made so it superseedes marketing
* and tracking utilities
*
* @author Renoir Boulanger <hello@renoirboulanger.com>
*
* See also https://gist.github.com/renoirb/db4b208b9a40a0c72ad5
*/
header('HTTP/1.1 200 OK');
header('X-Powered-By: you');
$accept = array_map(
function($http_accept_lang){
$lang_code = strpos($http_accept_lang, ';');
return ($lang_code > 1) ? substr($http_accept_lang, 0, $lang_code) : $http_accept_lang;
},
explode(',', $_SERVER['HTTP_ACCEPT'])
);
foreach($accept as $k => $v){
if($v === '*/*') {
unset($accept[$k]);
}
}
header('Content-Type: '.$accept[0]);
header('X-Accepted-keywords: ' . join(',', $accept));
$out = '';
if(in_array('text/html', $accept)) {
$out = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>No banner, please</title>
<style>
*,*::before,*::after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;}
::selection { background:#fe57a1; color: #fff; text-shadow:none; }
html { font-family:"Helvetica Neue", Helvetica, Arial, sans-serif; }
html { color:#737373; background:#f0f0f0; }
body { margin:0; }
head { display:none; }
html, body { height:100%; }
h1 { font-size:2em; text-align:center; text-shadow:1px 1px 3px #a7a7a7; margin:0; }
body { display:flex; align-items:center; justify-content:center; }
body > div { height:100%; width:100%; }
</style>
</head>
<body><div class="container"><h1 title="No banner, plz">(ಠ益ಠ)</h1></div></body>
</html>
HTML;
} else {
header('X-Message: No banner, please');
}
echo $out; // EOF, no closing PHP tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment