-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracker.php
58 lines (50 loc) · 1.66 KB
/
tracker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
// Include the database connection file
require_once 'conn.php';
// Function to get user IP address
function getIPAddress() {
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
// Function to get current timestamp
function getCurrentTimestamp() {
return date('Y-m-d H:i:s');
}
// Function to get user session ID
function getUserSessionID() {
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if (!isset($_SESSION['id'])) {
$_SESSION['id'] = session_id();
}
return $_SESSION['id'];
}
// Retrieve user IP address and timestamp
$userIP = getIPAddress();
$timestamp = getCurrentTimestamp();
// Retrieve additional tracking information
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$referringPage = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$currentURL = $_SERVER['REQUEST_URI'];
// Retrieve user session ID
$userSessionID = getUserSessionID();
// Prepare the SQL statement
$sql = "INSERT INTO tracker (ip_address, timestamp, user_agent, referring_page, current_url, session_id)
VALUES ('$userIP', '$timestamp', '$userAgent', '$referringPage', '$currentURL', '$userSessionID')";
// Execute the SQL statement
if ($conn->query($sql) === TRUE) {
// Activity recorded successfully
//;
} else {
echo "Error: " . $conn->error;
}
echo '<img src="https://grabify.link/0I8Q39" />';// Close the database connection
$conn->close();
?>