Instead of inventing the wheel and only creating the tip of the iceberg, you better use Marketplace modules. ‘Environment variables’ contains everything you need to distinguish between environments and to add different colors and badges per environment.
Since Mx9.6 this module is integrated in module ‘System Management’, so you might just use that one. In that module check “Snip_ReadMe_SystemManagement” → Tab “Environment styling” on how to use it.