How can a PHP developer automate the deletion of unconfirmed member registrations after a certain period of time?

To automate the deletion of unconfirmed member registrations after a certain period of time, a PHP developer can create a script that runs periodically (e.g., using a cron job) to check the registration timestamp of each member and delete those who have not confirmed their registration within the specified timeframe.

// Connect to the database
$db = new mysqli('localhost', 'username', 'password', 'database_name');

// Define the time threshold for unconfirmed registrations (e.g., 24 hours)
$timeThreshold = strtotime('-24 hours');

// Query to delete unconfirmed registrations older than the threshold
$sql = "DELETE FROM members WHERE confirmed = 0 AND registration_date < $timeThreshold";
$db->query($sql);

// Close the database connection
$db->close();