How can PHP be used to generate unique tokens for user authentication in a MySQL database?

To generate unique tokens for user authentication in a MySQL database using PHP, you can use the `uniqid()` function combined with hashing functions like `md5` or `sha1`. This will create a unique token that can be stored in the database and used for user authentication.

<?php
// Generate a unique token
$token = md5(uniqid(rand(), true));

// Store the token in the database
// Assuming $conn is the MySQL database connection
$query = "INSERT INTO users (token) VALUES ('$token')";
$result = mysqli_query($conn, $query);

if($result) {
    echo "Token generated and stored successfully!";
} else {
    echo "Error storing token in the database";
}
?>