• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

IP Logger PHP for MyAcc

Svira

Active Member
Joined
Jan 27, 2008
Messages
267
Solutions
11
Reaction score
36
What is this?
IPlogger is an Internet tool that is used to collect the IP addresses of users who visit a given website or click on a link redirecting to this website.

IPlogger works by generating a special link that contains a tracking code. Then, when someone clicks on such a link, their IP address information will be stored in a file or database on IPlogger's server.

IPlogger is mainly used for marketing purposes, analyzing website traffic and monitoring the activity of undesirable users. However, due to the fact that some people may use it for unethical or criminal purposes, many ISPs block access to websites containing IPlogger tracking codes.


add in index:
PHP:
<?php
$servername = "localhost";
$username = "nazwa_uzytkownika";
$password = "haslo_uzytkownika";
$dbname = "ots";

// Stwórz połączenie z bazą danych
$conn = new mysqli($servername, $username, $password, $dbname);

// Sprawdź, czy udało się połączyć z bazą danych
if ($conn->connect_error) {
  die("Nie udało się połączyć z bazą danych: " . $conn->connect_error);
}

// Pobierz adres IP użytkownika
$ip = $_SERVER['REMOTE_ADDR'];

// Pobierz ciąg znaków z informacjami o przeglądarce internetowej
$user_agent = $_SERVER['HTTP_USER_AGENT'];

// Przygotuj zapytanie SQL do dodania wpisu do bazy danych
$sql = "INSERT INTO iplogs (ip, user_agent) VALUES ('$ip', '$user_agent')";

// Wykonaj zapytanie do bazy danych
if ($conn->query($sql) === TRUE) {
  echo "Adres IP został zalogowany.";
} else {
  echo "Wystąpił błąd podczas zapisywania adresu IP: " . $conn->error;
}

// Zamknij połączenie z bazą danych
$conn->close();
?>

SQL:

SQL:
CREATE DATABASE IF NOT EXISTS ots;
USE ots;

CREATE TABLE IF NOT EXISTS iplogs (
  id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  ip VARCHAR(45) NOT NULL,
  user_agent TEXT,
  timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Remember to inform your users about data collection and tracking!

I
f you are a professional and know what you are doing, you can use the following more advanced code that retrieves information from which website the user visited us and what traffic he performed on our website

PHP:
<?php
// konfiguracja połączenia z bazą danych
$db_host = 'localhost';
$db_user = 'user';
$db_pass = 'password';
$db_name = 'iplogs';

// ustawienie strefy czasowej
date_default_timezone_set('Europe/Warsaw');

// funkcja zapisująca dane do bazy danych
function save_to_database($ip_address, $user_agent, $referrer, $request_uri, $request_method) {
    global $db_host, $db_user, $db_pass, $db_name;

    // połączenie z bazą danych
    $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);

    // sprawdzenie czy połączenie się udało
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }

    // przygotowanie zapytania SQL
    $sql = "INSERT INTO logs (ip_address, user_agent, referrer, request_uri, request_method, datetime) VALUES ('$ip_address', '$user_agent', '$referrer', '$request_uri', '$request_method', NOW())";

    // wykonanie zapytania SQL
    if (mysqli_query($conn, $sql)) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    // zamknięcie połączenia z bazą danych
    mysqli_close($conn);
}

// pobranie adresu IP użytkownika
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip_address = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip_address = $_SERVER['REMOTE_ADDR'];
}

// pobranie informacji o przeglądarce i systemie operacyjnym użytkownika
$user_agent = $_SERVER['HTTP_USER_AGENT'];

// pobranie strony, z której użytkownik przyszedł
if (isset($_SERVER['HTTP_REFERER'])) {
    $referrer = $_SERVER['HTTP_REFERER'];
} else {
    $referrer = '';
}

// pobranie URI, na który użytkownik wszedł
$request_uri = $_SERVER['REQUEST_URI'];

// pobranie metody HTTP, którą użytkownik użył
$request_method = $_SERVER['REQUEST_METHOD'];

// zapisanie danych do bazy danych
save_to_database($ip_address, $user_agent, $referrer, $request_uri, $request_method);
?>

SQL:
CREATE TABLE logs (
  id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  ip_address VARCHAR(50) NOT NULL,
  user_agent TEXT NOT NULL,
  referrer TEXT,
  request_uri TEXT NOT NULL,
  request_method VARCHAR(10) NOT NULL,
  datetime DATETIME NOT NULL
);
 
Last edited:
myaac already has connection with db, no need to connect again.

I allowed me to adjust the code a bit, thus optimize it.

Adding this at the end of index.php should be enough:
PHP:
// pobranie adresu IP użytkownika
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip_address = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip_address = $_SERVER['REMOTE_ADDR'];
}

// pobranie informacji o przeglądarce i systemie operacyjnym użytkownika
$user_agent = $_SERVER['HTTP_USER_AGENT'];

// pobranie strony, z której użytkownik przyszedł
if (isset($_SERVER['HTTP_REFERER'])) {
    $referrer = $_SERVER['HTTP_REFERER'];
} else {
    $referrer = '';
}

// pobranie URI, na który użytkownik wszedł
$request_uri = $_SERVER['REQUEST_URI'];

// pobranie metody HTTP, którą użytkownik użył
$request_method = $_SERVER['REQUEST_METHOD'];

$sql = "INSERT INTO logs (ip_address, user_agent, referrer, request_uri, request_method, datetime) VALUES ('$ip_address', '$user_agent', '$referrer', '$request_uri', '$request_method', NOW())";

$db->query($sql);

Although, thanks for useful piece of code.
 
Back
Top