Created
January 5, 2016 15:56
-
-
Save cmaas/b456f7285aa7a2455a19 to your computer and use it in GitHub Desktop.
Function to track visitor information (e. g. pixel tracker)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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