A little script that runs via PHP to log a bunch of details of the user who hits the URL given to them. Everything it can grab gets logged to a file named: visitor_log.csv
<?php
// Function to get the client IP address
function get_client_ip() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
// Function to get user-agent (browser)
function get_user_agent() {
return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'UNKNOWN';
}
// Function to get server info
function get_server_info() {
return php_uname();
}
// Function to log visitor information to CSV file
function log_visitor_info() {
$log_file = 'visitor_log.csv';
// Check if the log file exists
if (!file_exists($log_file)) {
// Add column titles if the file doesn't exist
$column_titles = array('Timestamp', 'IP Address', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', 'User-Agent', 'Server Info', 'Path/URL');
$fp = fopen($log_file, 'a');
fputcsv($fp, $column_titles);
fclose($fp);
}
$ip_address = get_client_ip();
$http_x_forwarded_for = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : 'Not provided';
$http_x_forwarded = isset($_SERVER['HTTP_X_FORWARDED']) ? $_SERVER['HTTP_X_FORWARDED'] : 'Not provided';
$http_forwarded_for = isset($_SERVER['HTTP_FORWARDED_FOR']) ? $_SERVER['HTTP_FORWARDED_FOR'] : 'Not provided';
$http_forwarded = isset($_SERVER['HTTP_FORWARDED']) ? $_SERVER['HTTP_FORWARDED'] : 'Not provided';
$remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'Not provided';
$user_agent = get_user_agent();
$machine_info = get_server_info();
$path_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'Not provided';
$timestamp = date('Y-m-d H:i:s');
$log_data = array($timestamp, $ip_address, $http_x_forwarded_for, $http_x_forwarded, $http_forwarded_for, $http_forwarded, $remote_addr, $user_agent, $machine_info, $path_url);
$fp = fopen($log_file, 'a');
fputcsv($fp, $log_data);
fclose($fp);
}
// Call the function to log visitor information
log_visitor_info();
// Forward the user to a different URL
header("Location: https://google.com");
?>