What are the security implications of storing user rights in sessions versus querying the database in PHP?
Storing user rights in sessions can potentially lead to security vulnerabilities if the session data is tampered with or hijacked. It is more secure to query the database each time to verify the user's rights before granting access to certain resources.
// Query the database to get user rights
$user_rights = query_database_for_user_rights($user_id);
// Check if user has the required rights
if ($user_rights['admin'] == 1) {
// Grant access to admin resources
} else {
// Redirect or show an error message
}