Skip to content

Instantly share code, notes, and snippets.

@cmaas
Created January 5, 2016 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmaas/b456f7285aa7a2455a19 to your computer and use it in GitHub Desktop.
Save cmaas/b456f7285aa7a2455a19 to your computer and use it in GitHub Desktop.
Function to track visitor information (e. g. pixel tracker)
// callback
function get_server_info($k) {
return '"' . (isset($_SERVER[$k]) ? $_SERVER[$k] : '-') . '"';
}
// format: 2016/01/06-15:38:40 10.0.0.1 "/p.gif?page=home" "Mozilla/5.0" "http://ref.co"
function track_visitor() {
if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$client_ip = $_SERVER['REMOTE_ADDR'];
} else {
$client_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
};
$client_infos = array(
'REQUEST_URI', 'HTTP_USER_AGENT', 'HTTP_REFERER'
);
$client = array_map('get_server_info', $client_infos);
$data = array(
date('Y/m/d-H:i:s', time()),
$client_ip
);
$log_info = array_merge($data, $client);
$log_str = implode(' ' , $log_info) . "\n";
@file_put_contents('./pixel.txt', $log_str, FILE_APPEND);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment