-
Notifications
You must be signed in to change notification settings - Fork 0
/
saver.php
28 lines (22 loc) · 1.12 KB
/
saver.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
<?php
$objConnection = new mysqli('<DATABASE_HOST>', '<DATABASE_USER>', '<DATABASE_PASSWORD>', '<DATABASE_NAME>');
$strTable = 'tblLogging';
// Check your server if these $SERVER-variables are available
$strIP = $_SERVER['REMOTE_ADDR'];
$strOrigin = $_SERVER['HTTP_REFERER'];
$strCountry = implode ('', file ("http://ip-api.com/csv/". $strIP . "?fields=countryCode"));
$strHash = hash('sha512', $strIP);
$objQuery = "INSERT INTO $strTable (ip, country, origin, hash) VALUES ('$strIP', '$strCountry', '$strOrigin', '$strHash')";
if (!$objConnection) {
die('Could not connect database: ' . mysqli_error());
}
if (mysqli_query($objConnection, $objQuery)) {
// You don't should display any messages here. If you show the message on the user screen the user knows that you
// save there privacy information.
} else {
// Disable the error messages in these section. It's only for debugging.
// If you don't disable, your users knows that you don't have a connection to your database server.
// echo "Error: " . $objQuery . "<br>" . mysqli_error($objConnection);
}
mysqli_close($objConnection);
?>