-
Notifications
You must be signed in to change notification settings - Fork 1
/
logPageHit.php
39 lines (35 loc) · 979 Bytes
/
logPageHit.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
<?php
require_once '../../includefolder/mysqlCredFor_canicvs_reaction.php';
function getIP(){
if (!empty($_SERVER["HTTP_CLIENT_IP"]))
{
//check for ip from share internet
$ip = $_SERVER["HTTP_CLIENT_IP"];
}
elseif (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
{
// Check for the Proxy User
$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else
{
$ip = $_SERVER["REMOTE_ADDR"];
}
// This will print user's real IP Address
// does't matter if user using proxy or not.
return $ip;
}
function logHit(){
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO pagehits (clientIP) VALUES ('" . getIP() . "')";
if ($conn->query($sql) === TRUE) {
return "Page hit successfully logged.";
} else {
return "Error: " . $sql . "<br>" . $conn->error;
}
}
echo logHit();
?>