How can PHP be used to gather visitor information for a visitor exchange service without requiring registration?

To gather visitor information for a visitor exchange service without requiring registration, you can use PHP to capture data such as IP address, user agent, and timestamps when a visitor accesses the site. This information can be stored in a database for future analysis and tracking without the need for user registration.

<?php
// Capture visitor information
$ip_address = $_SERVER['REMOTE_ADDR'];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$timestamp = date("Y-m-d H:i:s");

// Store visitor information in a database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "visitor_data";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO visitors (ip_address, user_agent, timestamp) VALUES ('$ip_address', '$user_agent', '$timestamp')";

if ($conn->query($sql) === TRUE) {
    echo "Visitor information captured successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>