How can PHP and SQL be effectively combined to identify and mark potentially suspicious activities, such as multiple usernames sharing the same IP address?

To identify and mark potentially suspicious activities, such as multiple usernames sharing the same IP address, you can use PHP to query the SQL database for any occurrences of this pattern. By checking the IP address associated with each username and counting the number of unique IP addresses, you can flag any instances where multiple usernames share the same IP address.

// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

// Query to identify multiple usernames sharing the same IP address
$sql = "SELECT ip_address, COUNT(DISTINCT username) AS num_users
        FROM user_activity
        GROUP BY ip_address
        HAVING num_users > 1";

$result = $conn->query($sql);

// Mark suspicious activities
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Multiple usernames sharing the same IP address: " . $row["ip_address"]. "<br>";
    }
} else {
    echo "No suspicious activities found.";
}

// Close database connection
$conn->close();