What is the recommended approach for updating the last login date in a user profile using PHP?

To update the last login date in a user profile using PHP, you can simply retrieve the current date and time and then update the corresponding field in the user's database record.

// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=your_database', 'username', 'password');

// Update the last login date for the current user
$user_id = $_SESSION['user_id']; // Assuming you have stored the user's ID in a session variable
$last_login = date('Y-m-d H:i:s');
$stmt = $pdo->prepare("UPDATE users SET last_login = :last_login WHERE id = :user_id");
$stmt->execute(array(':last_login' => $last_login, ':user_id' => $user_id));